Part Number Hot Search : 
2SD1655 AGRF600 DS3019 D16510 02500 16PITE1 SXX18 LM3950
Product Description
Full Text Search
 

To Download PD78044F Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  application note printed in japan 78k/0 series 8-bit single-chip microcontrollers basics (ii) m PD78044F subseries m pd78044h subseries m pd780208 subseries m pd780228 subseries document no. u10121ej3v0an00 (3rd edition) date published august 1997 j 1993

summary of contents chapter 1 overview ....................................................................................................................... 1 chapter 2 software basics ....................................................................................................... 15 chapter 3 system clock switching application .............................................................. 37 chapter 4 watchdog timer application ............................................................................... 51 chapter 5 16-bit timer/event counter application ......................................................... 59 chapter 6 8-bit timer/event counter application ........................................................... 101 chapter 7 watch timer application ....................................................................................... 117 chapter 8 serial interface application ............................................................................. 127 chapter 9 a/d converter application ................................................................................... 215 chapter 10 applications of fip controller/driver ......................................................... 249 chapter 11 applications of 6-bit up/down counter .......................................................... 275 appendix a spd chart description ............................................................................................ 281 appendix b revision history ......................................................................................................... 289
fip is a trademark of nec corporation. eeprom and iebus are trademarks of nec corporation. notes for cmos devices 1 precaution against esd for semiconductors note: strong electric field, when exposed to a mos device, can cause destruction of the gate oxide and ultimately degrade the device operation. steps must be taken to stop generation of static electricity as much as possible, and quickly dissipate it once, when it has occurred. environmental control must be adequate. when it is dry, humidifier should be used. it is recommended to avoid using insulators that easily build static electricity. semiconductor devices must be stored and transported in an anti-static container, static shielding bag or conductive material. all test and measurement tools including work bench and floor should be grounded. the operator should be grounded using wrist strap. semiconductor devices must not be touched with bare hands. similar precautions need to be taken for pw boards with semiconductor devices on it. 2 handling of unused input pins for cmos note: no connection for cmos device inputs can be cause of malfunction. if no connection is provided to the input pins, it is possible that an internal input level may be generated due to noise, etc., hence causing malfunction. cmos devices behave differently than bipolar or nmos devices. input levels of cmos devices must be fixed high or low by using a pull-up or pull-down circuitry. each unused pin should be connected to v dd or gnd with a resistor, if it is considered to have a possibility of being an output pin. all handling related to the unused pins must be judged device by device and related specifications governing the devices. 3 status before initialization of mos devices note: power-on does not necessarily define initial status of mos device. production process of mos does not define the initial operation status of the device. immediately after the power source is turned on, the devices with reset function have not yet been initialized. hence, power-on does not guarantee out-pin levels, i/o settings or contents of registers. device is not initialized until the reset signal is received. reset operation must be executed immediately after power-on for devices having reset function.
the export of these products from japan is regulated by the japanese government. the export of some or all of these products may be prohibited without governmental license. to export or re-export some or all of these products from a country other than japan may also be prohibited without a license from that country. please call an nec sales representative. the application circuits and their parameters are for reference only and are not intended for use in actual design-ins. the information in this document is subject to change without notice. no part of this document may be copied or reproduced in any form or by any means without the prior written consent of nec corporation. nec corporation assumes no responsibility for any errors which may appear in this document. nec corporation does not assume any liability for infringement of patents, copyrights or other intellectual property rights of third parties by or arising from use of a device described herein or any other liability arising from use of such device. no license, either express, implied or otherwise, is granted under any patents, copyrights or other intellectual property rights of nec corporation or others. while nec corporation has been making continuous effort to enhance the reliability of its semiconductor devices, the possibility of defects cannot be eliminated entirely. to minimize risks of damage or injury to persons or property arising from a defect in an nec semiconductor device, customers must incorporate sufficient safety measures in its design, such as redundancy, fire-containment, and anti-failure features. nec devices are classified into the following three quality grades: "standard", "special", and "specific". the specific quality grade applies only to devices developed based on a customer designated "quality assurance program" for a specific application. the recommended applications of a device depend on its quality grade, as indicated below. customers must check the quality grade of each device before using it in a particular application. standard: computers, office equipment, communications equipment, test and measurement equipment, audio and visual equipment, home electronic appliances, machine tools, personal electronic equipment and industrial robots special: transportation equipment (automobiles, trains, ships, etc.), traffic control systems, anti-disaster systems, anti-crime systems, safety equipment and medical equipment (not specifically designed for life support) specific: aircrafts, aerospace equipment, submersible repeaters, nuclear reactor control systems, life support systems or medical equipment for life support, etc. the quality grade of nec devices is "standard" unless otherwise specified in nec's data sheets or data books. if customers intend to use nec devices for applications other than those specified for standard quality grade, they should contact an nec sales representative in advance. anti-radioactive design is not implemented in this product. m7 96. 5
nec electronics inc. (u.s.) santa clara, california tel: 800-366-9782 fax: 800-729-9288 nec electronics (germany) gmbh duesseldorf, germany tel: 0211-65 03 02 fax: 0211-65 03 490 nec electronics (uk) ltd. milton keynes, uk tel: 01908-691-133 fax: 01908-670-290 nec electronics italiana s.r.1. milano, italy tel: 02-66 75 41 fax: 02-66 75 42 99 nec electronics hong kong ltd. hong kong tel: 2886-9318 fax: 2886-9022/9044 nec electronics hong kong ltd. seoul branch seoul, korea tel: 02-528-0303 fax: 02-528-4411 nec electronics singapore pte. ltd. united square, singapore 1130 tel: 253-8311 fax: 250-3583 nec electronics taiwan ltd. taipei, taiwan tel: 02-719-2377 fax: 02-719-5951 nec do brasil s.a. sao paulo-sp, brasil tel: 011-889-1680 fax: 011-889-1689 nec electronics (germany) gmbh benelux office eindhoven, the netherlands tel: 040-2445845 fax: 040-2444580 nec electronics (france) s.a. velizy-villacoublay, france tel: 01-30-67 58 00 fax: 01-30-67 58 99 nec electronics (france) s.a. spain office madrid, spain tel: 01-504-2787 fax: 01-504-2860 nec electronics (germany) gmbh scandinavia office taeby, sweden tel: 08-63 80 820 fax: 08-63 80 388 regional information some information contained in this document may vary from country to country. before using any nec product in your application, please contact the nec office in your country to obtain a list of authorized representatives and distributors. they will verify: ? device availability ? ordering information ? product release schedule ? availability of related technical literature ? development environment specifications (for example, specifications for third-party tools and components, host computers, power plugs, ac supply voltages, and so forth) ? network requirements in addition, trademarks, registered trademarks, export restrictions, and other legal issues may also vary from country to country. j96. 8
major changes page description throughout the following products have been added as applicable products: m PD78044F, m pd78044h, and m pd780228 subseries, m pd780206, and m pd780208 the following subseries have been dropped as applicable products: m pd78024 and m pd78044a subseries p.37, 38 the following register formats and tables are described separately according to the p.39, 40 products: p.53, 54 tables 3-1 and 3-2 , figures 3-1 , 3-2 , 4-2 , 4-3 , 8-1 , 8-2 , 9-1 , 9-2 , 10-7 , and 10-8 p.128, 129 p.216, 217 p.258, 260 p.1 the following subseries have been added in section 1.1 . m pd78075b, m pd78075by, m pd780018, m pd780018y, m pd780058, m pd780058y, m pd78058f, m pd78058fy, m pd780034, m pd780034y, m pd780024, m pd780024y, m pd78014h, m pd780964, m pd780924, m pd780228, m pd78044h, m PD78044F, m pd780308, m pd780308y, m pd78064b, m pd78098b, m pd780973, m pd780805 subseries, and m pd78p0914 p.40 table 3-3 has been added. p.53 note 2 and caution 2 have been added to figure 4-2 . p.55 figure 4-4 has been added. p.63 a caution has been added to figure 5-5 . p.127 table 8-2 has been added. p.130 note 4 and a caution have been added to figure 8-3 . p.139 a caution has been added to figure 8-9 . p.141 section 8.1 the m pd6252 has been defined as a product for maintenance purposes only. p.219 figure 9-4 has been added. the mark shows major revised points.
[memo]
preface target users this application note is for engineers who wish to understand 78k/0 series devices and design application programs using these devices. ? target products in each subseries m PD78044F subseries : m pd78042f, m pd78043f, m PD78044F, m pd78045f, m pd78p048a m pd78044h subseries : m pd78044h, m pd78045h, m pd78046h, m pd78p048b note m pd780208 subseries : m pd780204, m pd780205, m pd780206, m pd780208, m pd78p0208 m pd780228 subseries : m pd780226 note , m pd780228 note , m pd78f0228 note note under development objective the purpose of this application note is to use program examples to help users to understand the basic functions of 78k/0 series devices. the program and hardware structures published here are illustrative examples and are not designed for mass production. organization this application note is broadly divided into the following areas. ? overview ? software ? hardware *
the following application notes are supported. document name document no. applicable subseries description japanese english 78k/0 series application iea-715 iea-1288 m pd78002, 78002y describes basic functions of 78k/0 note, basics (i) m pd78014, 78014y series products, using program m pd78018f, 78018fy examples. 78k/0 series application u10121j this m PD78044F note, basics (ii) manual m pd78044h m pd780208 m pd780228 78k/0 series application iea-767 u10182e m pd78054, 78054y note, basics (iii) m pd78064, 78064y m pd78078, 78078y m pd78083 m pd78098 78k/0 series application iea-718 iea-1289 all subseries of 78k/0 series describes the floating-point note, floating-point operation except for m pd78002 and operation application programs of program m pd78002y subseries 78k/0 series products. m pd78014 series application iea-744 iea-1301 m pd78014 describes the functions and note, electronic notes only the m pd78014 and configuration of electronic notes, m pd78p014 are applicable. using m pd78014 subseries products as examples. caution in this application note, the application examples and program listings are written for the main system clock operating at 4.19 mhz. they are not for the main system clock operating at 5.0 mhz.
reading this note this application note is for 78k/0 series products, but each subseries has different functions. each subseries is described in the chapters listed in the following table. sample applications for each subseries are given in those chapters indicated by circles. subseries m PD78044F m pd78044h m pd780208 m pd780228 chapter chapter 1 overview o o o o chapter 2 software basics o o o o chapter 3 system clock switching application o o o o chapter 4 watchdog timer application o o o o chapter 5 16-bit timer/event counter application o o o - chapter 6 8-bit timer/event counter application o o o - chapter 7 watch timer application o o o - chapter 8 serial interface application o o o - chapter 9 a/d converter application o o o o chapter 10 applications of fip controller/driver o o o o chapter 11 applications of 6-bit up/down counter o - - - legend significance of the : the left side is high-order data and data description the right side is low-order data. active-low description : xxx (line above pin and signal names) note : explanation of the note attached to the text. caution : contents that should be read carefully remark : supplemental explanation of the text number descriptions : binary numbers ............. xxxx or xxxxb decimal numbers .......... xxxx hexadecimal numbers .. xxxxh application area ? consumer product field
related documents the related documents indicated in this publication may include preliminary versions. however, preliminary versions are not marked as such. ? common documents document name document number japanese english 78k/0 series application note, basics (ii) u10121j this manual 78k/0 series user's manual, instruction u12326j ieu-1372 78k/0 series instruction set u10904j - 78k/0 series instruction table u10903j - ? documents for m PD78044F subseries document name document number japanese english m pd78042f, 78043f, 78044f, 78045f data sheet u10700j u10700e m pd78p048a data sheet u10611j u10611e m PD78044F subseries user's manual u10908j u10908e m pd78044a, 78044f subseries special function register table u10701j - ? documents for m pd78044h subseries document name document number japanese english m pd78044h, 78045h, 78046h data sheet u10865j u10865e m pd78p048b data sheet to be created to be created m pd78044h subseries user's manual u11756j u11756e ? documents for m pd780208 subseries document name document number japanese english m pd780204, 780205, 780206, 780208 data sheet u10436j u10436e m pd78p0208 data sheet u11295j u11295e m pd780208 subseries user's manual u11302j u11302e m pd780208 subseries special function register table u10997j - *
documents for m pd780228 subseries document name document number japanese english m pd780226, 780228 data sheet u11797j u11797e m pd78f0228 preliminary product information u11971j u11971e m pd780228 subseries users manual u12012j u12012e the above documents may be revised without notice. use the latest versions when you design an application system. *
[memo]
- i - contents chapter 1 overview ....................................................................................................................... 1 1.1 78k/0 series product development ......................................................... 1 1.2 78k/0 series features .................................................................................... 3 chapter 2 software basics ....................................................................................................... 15 2.1 data transfer ................................................................................................... 15 2.2 data comparison .............................................................................................. 16 2.3 decimal addition .............................................................................................. 17 2.4 decimal subtraction ...................................................................................... 24 2.5 binary-to-decimal conversion .................................................................. 26 2.6 bit operation manipulation instruction .............................................. 28 2.7 binary multiplication (16 bits x 16 bits) .................................................. 29 2.8 binary division (32 bits/16 bits) ................................................................... 33 chapter 3 system clock switching application .............................................................. 37 3.1 switching pcc after reset ......................................................................... 46 3.2 switching during power on/off ............................................................... 47 chapter 4 watchdog timer application ............................................................................... 51 4.1 setting the watchdog timer mode ......................................................... 56 4.2 interval timer mode setting ...................................................................... 58 chapter 5 16-bit timer/event counter application ......................................................... 59 5.1 interval timer setting .................................................................................. 65 5.2 pwm output ........................................................................................................ 67 5.3 remote control reception ........................................................................ 69 5.3.1 remote control reception by a counter clear ........................................ 72 5.3.2 remote control reception by pwm output and free running .............. 86
- ii - chapter 6 8-bit timer/event counter application ........................................................... 101 6.1 setting the interval timer ......................................................................... 106 6.1.1 setting an 8-bit timer ................................................................................ 107 6.1.2 setting the 16-bit timer ............................................................................. 109 6.2 musical scale generation ........................................................................... 111 chapter 7 watch timer application ....................................................................................... 117 7.1 watch and led display program .............................................................. 119 chapter 8 serial interface application ............................................................................. 127 8.1 interfacing with eeprom tm ( m pd6252) ...................................................... 141 8.1.1 communication in the 2-wire serial i/o mode ......................................... 143 8.2 interfacing with the osd lsi ( m pd6451a) ................................................ 153 8.3 sbi mode interface ......................................................................................... 158 8.3.1 application as a master cpu .................................................................... 160 8.3.2 application as a slave cpu ....................................................................... 169 8.4 3-wire serial i/o mode interface .............................................................. 173 8.4.1 application as a master cpu .................................................................... 174 8.4.2 application as a slave cpu ....................................................................... 178 8.5 half-duplex asynchronous communication ....................................... 182 8.5.1 half-duplex asynchronous communication of the 3-wire mode ............. 182 8.5.2 half-duplex asynchronous communication in the sbi mode .................. 197 chapter 9 a/d converter application ................................................................................... 215 9.1 level meter ........................................................................................................ 220 9.2 thermometer ..................................................................................................... 229 9.3 analog key input .............................................................................................. 239 9.4 4-channel input a/d conversion ............................................................... 245 chapter 10 applications of fip controller/driver ......................................................... 249 10.1 12-digit display for fip and key input .................................................... 262 10.1.1 12-digit fip display ................................................................................... 263 10.1.2 key input .................................................................................................... 266 10.1.3 description of package .............................................................................. 268 10.1.4 example of use .......................................................................................... 270 10.1.5 spd chart .................................................................................................. 272 10.1.6 program listing .......................................................................................... 273
- iii - chapter 11 applications of 6-bit up/down counter ......................................................... 275 11.1 1-second counter ........................................................................................... 277 appendix a spd chart description ........................................................................................... 281 appendix b revision history ........................................................................................................ 289
- iv - list of figures (1/4) figure no. title page 1-1. block diagram of the m PD78044F subseries .................................................................. 4 1-2. block diagram of the m pd78044h subseries .................................................................. 7 1-3. block diagram of the m pd780208 subseries .................................................................. 10 1-4. block diagram of the m pd780228 subseries .................................................................. 13 2-1. data exchange .................................................................................................................. 15 2-2. data comparison .............................................................................................................. 16 2-3. decimal addition ............................................................................................................... 17 2-4. decimal subtraction .......................................................................................................... 24 2-5. binary-to-decimal conversion .......................................................................................... 26 2-6. bit operation ...................................................................................................................... 28 2-7. binary multiplication .......................................................................................................... 29 2-8. binary division ................................................................................................................... 33 3-1. format of the processor clock control register ( m PD78044F, m pd78044h, and m pd780208 subseries) ................................................ 39 3-2. format of the processor clock control register ( m pd780228 subseries) .................... 40 3-3. format of the display mode register 0 ( m PD78044F and m pd78044h subseries) ...... 41 3-4. format of the display mode register 0 ( m pd780208 subseries) ................................... 42 3-5. format of the display mode register 1 ( m PD78044F and m pd78044h subseries) ...... 44 3-6. format of the display mode register 1 ( m pd780208 subseries) ................................... 45 3-7. cpu clock switching after reset ( m PD78044F subseries) ......................................... 46 3-8. example of the system clock switching circuit .............................................................. 47 3-9. system clock switching during power on and off ( m PD78044F subseries) ................ 48 4-1. format of timer clock selection register 2 ( m PD78044F, m pd78044h, and m pd780208 subseries) ................................................ 52 4-2. format of the watchdog timer mode register ( m PD78044F, m pd78044h, and m pd780208 subseries) ................................................ 53 4-3. format of the watchdog timer mode register ( m pd780228 subseries) ....................... 54 4-4. format of the watchdog timer clock selection register (only for the m pd780228 subseries) ............................................................................... 55 4-5. count timing of the watchdog timer .............................................................................. 58 5-1. format of timer clock selection register 0 .................................................................... 60 5-2. format of the 16-bit timer mode control register ......................................................... 61
- v - list of figures (2/4) figure no. title page 5-3. format of the 16-bit timer output control register ....................................................... 62 5-4. format of the port mode register 3 ................................................................................. 63 5-5. format of the external interrupt mode register .............................................................. 63 5-6. format of the sampling clock selection register ........................................................... 64 5-7. example of the remote control receiving circuit .......................................................... 69 5-8. ic output signal for remote control transmission ........................................................ 70 5-9. output signal of the receiving preamplifier .................................................................... 71 5-10. sampling the remote control signal ............................................................................... 72 6-1. format of timer clock selection register 1 .................................................................... 102 6-2. format of the 8-bit timer mode control register ........................................................... 103 6-3. format of the 8-bit timer output control register ......................................................... 104 6-4. format of port mode register 3 ....................................................................................... 105 6-5. count timing of an 8-bit timer ........................................................................................ 106 6-6. musical scale generation circuit ..................................................................................... 111 6-7. timer output and interval ................................................................................................. 111 7-1. format of timer clock selection register 2 .................................................................... 117 7-2. format of the watch timer mode control register ........................................................ 118 7-3. schematic of watch data ................................................................................................. 119 7-4. led display timing ........................................................................................................... 120 7-5. example circuit of the watch timer ................................................................................ 120 8-1. format of timer clock selection register 3 ( m PD78044F and m pd780208 subseries) ........................................................................ 128 8-2. format of timer clock selection register 3 ( m pd78044h subseries) .......................... 129 8-3. format of serial operating mode register 0 (only for the m PD78044F and m pd780208 subseries) ................................................... 130 8-4. format of the serial operating mode register 1 ............................................................ ( m PD78044F and m pd780208 subseries) ........................................................................ 132 8-5. format of the serial operating mode register 1 ( m pd78044h subseries) ................... 133 8-6. format of the interrupt timing setting register (only for the m PD78044F and m d780208 subseries) ...................................................... 134 8-7. format of the serial bus interface control register (only for the m PD78044F and m pd780208 subseries) ................................................... 135 8-8. format of the automatic data transmit/receive control register (only for the m PD78044F and m pd780208 subseries) ................................................... 137
- vi - list of figures (3/4) figure no. title page 8-9. format of the automatic data transmit/receive interval setting register (only for the m PD78044F and m pd780208 subseries) ................................................... 138 8-10. m pd6252 pin configuration .............................................................................................. 141 8-11. m pd6252 connection example ......................................................................................... 143 8-12. m pd6252 communication format .................................................................................... 145 8-13. connection example with m pd6451a .............................................................................. 153 8-14. m pd6451a communication format .................................................................................. 153 8-15. connection example of the sbi mode ............................................................................. 158 8-16. sbi mode communication format ................................................................................... 159 8-17. timed out ack signal ...................................................................................................... 160 8-18. bus line test .................................................................................................................... 160 8-19. connection example of the 3-wire serial i/o mode ....................................................... 173 8-20. communication format of the 3-wire serial i/o mode ................................................... 173 8-21. busy signal output ........................................................................................................... 178 8-22. system structure (3-wire mode) ...................................................................................... 182 8-23. 3-wire mode transmission format .................................................................................. 183 8-24. 3-wire mode reception format ....................................................................................... 184 8-25. system structure (sbi mode) ........................................................................................... 197 8-26. sbi mode transmission format ....................................................................................... 198 8-27. sbi mode reception format ............................................................................................ 199 9-1. format of the a/d converter mode register ( m PD78044F, m pd78044h, and m pd780208 subseries) ................................................ 216 9-2. format of the a/d converter mode register ( m pd780228 subseries) .......................... 217 9-3. format of the a/d converter input selection register ( m PD78044F, m pd78044h, and m pd780208 subseries) ................................................ 218 9-4. format of the analog input channel specification register (only for the m pd780228 subseries) ............................................................................... 219 9-5. level meter circuit example ............................................................................................. 220 9-6. a/d conversion result and led display ......................................................................... 220 9-7. conceptual diagram of the peak hold ............................................................................. 221 9-8. thermometer circuit example .......................................................................................... 229 9-9. temperature and output characteristics ......................................................................... 230 9-10. analog key input circuit example .................................................................................... 240 9-11. timing chart in the 4-channel scanning mode ............................................................... 245
- vii - list of figures (4/4) figure no. title page 10-1. format of display mode register 0 ( m PD78044F and m pd78044h subseries) ............ 251 10-2. format of display mode register 0 ( m pd780208 subseries) ......................................... 252 10-3. format of display mode register 0 ( m pd780228 subseries) ......................................... 254 10-4. format of display mode register 1 ( m PD78044F and m pd78044h subseries) ............ 255 10-5. format of display mode register 1 ( m pd780208 subseries) ......................................... 256 10-6. format of display mode register 1 ( m pd780228 subseries) ......................................... 257 10-7. format of display mode register 2 ( m pd780208 subseries) ......................................... 258 10-8. format of display mode register 2 ( m pd780228 subseries) ......................................... 260 10-9. fip controller operation timing ....................................................................................... 261 10-10. configuration of 12-digit fip display and key input ....................................................... 262 10-11. pin layout for 9-segment display .................................................................................... 264 10-12. relationship between contents of display data memory and segment output ........... 265 10-13. display example ................................................................................................................ 266 10-14. key interrupt timing chart ............................................................................................... 267 10-15. compensating for chattering ............................................................................................ 268 11-1. block diagram of 6-bit up/down counter ....................................................................... 275 11-2. format of 6-bit up/down counter control register ........................................................ 276
- viii - list of tables table no. title page 1-1. function overview of the m PD78044F subseries ............................................................ 5 1-2. function overview of the m pd78044h subseries ........................................................... 8 1-3. function overview of the m pd780208 subseries ............................................................ 11 1-4. function overview of the m pd780228 subseries ............................................................ 14 3-1. maximum time required to change the cpu clock ( m PD78044F, m pd78044h, and m pd780208 subseries) ................................................ 37 3-2. maximum time required to change the cpu clock ( m pd780228 subseries) ............. 38 3-3. relationship between the cpu clock and minimum instruction execution time .......... 40 5-1. valid time for input signal ............................................................................................... 72 5-2. valid time of the input signal .......................................................................................... 86 6-1. musical scale and frequencies ........................................................................................ 112 8-1. available serial interface channels in each subseries .................................................. 127 8-2. serial interface registers ................................................................................................. 127 8-3. description of m pd6252 pins ............................................................................................ 142 8-4. m pd6252 command list ................................................................................................... 144 8-5. sbi mode signal list ......................................................................................................... 159 9-1. a/d conversion values and temperatures ..................................................................... 231 9-2. input voltages and key codes ......................................................................................... 239 9-3. resistances of r1 to r15 ................................................................................................. 240 10-1. differences between m PD78044F, m pd78044h, m pd780208, and m pd780228 subseries ...................................................................................................... 250 a-1. comparison of spd symbols and flowcharts ................................................................. 281
1 chapter 1 overview chapter 1 overview 1.1 78k/0 series product development the 78k/0 series products were developed as shown below. the subseries names are indicated in frames. note being planned * m pd78083 m PD78044F m pd78064 m pd78098 m pd78098b m pd78p0914 m pd780973 m pd78064b m pd780308 m pd78044h m pd780228 m pd780208 m pd780924 m pd780964 m pd78002 m pd780001 m pd78014 m pd78018f m pd78014h m pd780024 m pd780034 m pd78054 m pd78058f m pd780058 m m pd78070a m pd78078 m pd78075b m pd78002y m pd78064y m pd780308y m pd78014y m pd78018fy m pd780024y m pd780034y m pd78054y m pd78058fy m pd780058y note m pd780018ay m m m m m m m m m m m m m m m m m m m m m m m pd78070ay m pd78078y m pd78075by products currently being mass-produced products under development y subseries products are compatible with the i 2 c bus. used for control for inverter control for fip tm driving for lcd driving compatible with iebus tm for meter control for lv 100-pin 100-pin 100-pin 100-pin 100-pin 100-pin 100-pin 64-pin 80-pin 80-pin 100-pin 100-pin 80-pin 80-pin 80-pin 80-pin 80-pin 80-pin 64-pin 64-pin 64-pin 64-pin 64-pin 64-pin 64-pin 64-pin 64-pin 42-/44-pin emi noise-reduced versions of the pd78078 a timer has been added to the pd78054 to enhance its external interface functions. rom-less versions of the pd78078 the serial i/o of the pd78078y has been enhanced by limiting its functions serial i/o of the pd78054 has been enhanced. emi noise-reduced versions of the pd78054 emi noise-reduced versions of the pd78054 a uart and d/a converter have been added to the pd78014 to enhance its i/o. the a/d converter of the pd780024 has been enhanced. the serial i/o of the pd78018f has been enhanced. emi noise-reduced versions of the pd78018f. emi noise-reduced version of the pd78018f low-voltage (1.8 v) versions of the pd78014. rom and ram variations have been enhanced. an a/d converter and 16-bit timer have been added to the pd78002. an a/d converter has been added to the pd78002. basic subseries for control the i/o and the fip controller/driver of the PD78044F have been enhanced. total indication output pins: 53 the i/o and the fip controller/driver of the pd78044h have been enhanced. total indication output pins: 48 n-ch open-drain i/o pins have been added to the PD78044F. total indication output pins: 34 basic subseries for fip driving. total indication output pins: 34 sio of the pd78064 has been enhanced. rom and ram have been extended. emi noise-reduced version of the pd78064 emi noise-reduced version of the pd78098 an iebus controller has been added to the pd78054. this product includes a controller/driver for driving car meters. this product includes the pwm output, lv digital code decoder, and hsync counter. basic subseries for lcd driving. these products include a uart. an a/d converter of the pd780924 has been enhanced. this product includes an inverter control circuit and uart. emi noise-reduced version. this product includes a uart and can operate at a low voltage (1.8 v). 78k/0 series
2 78k/0 series application note the table below shows the main differences between subseries. function rom timer 8-bit 10-bit 8-bit minimum external serial interface i/o subseries name capacity 8-bit 16-bit watch wdt a/d a/d d/a v dd expansion m pd78075b 32k-40 k 4 ch 1 ch 1 ch 1 ch 8 ch - 2 ch 3 ch (uart: 1 ch) 88 pins 1.8 v o m pd78078 48k-60k m pd78070a - 61 pins 2.7 v m pd780058 24k-60k 2 ch 2 ch 3ch (time-multiplexing 68 pins 1.8 v uart: 1ch) m pd78058f 48k-60k 3 ch (uart: 1 ch) 69 pins 2.7 v m pd78054 16k-60k 2.0 v m pd780034 8k-32k - 8 ch - 51 pins 1.8 v m pd780024 8 ch - m pd78014h 2 ch 53 pins m pd78018f 8k-60k m pd78014 8k-32k 2.7 v m pd780001 8k - - 1 ch 39 pins - m pd78002 8k-16k 1 ch - 53 pins o m pd78083 - 8 ch 1 ch (uart: 1 ch) 33 pins 1.8 v - m pd780964 8k-32k 3 ch note - 1 ch - 8 ch - 2 ch (uart: 2 ch) 47 pins 2.7 v o m pd780924 8 ch - m pd780208 32k-60k 2 ch 1 ch 1 ch 1 ch 8 ch - - 2 ch 74 pins 2.7 v - m pd780228 48k-60k 3 ch - - 1 ch 72 pins 4.5 v m pd78044h 32k-48k 2 ch 1 ch 1 ch 68 pins 2.7 v m PD78044F 16k-40k 2 ch m pd780308 48k-60k 2 ch 1 ch 1 ch 1 ch 8 ch - - 3ch (time-multiplexing 57 pins 2.0 v - uart: 1ch) m pd78064b 32k 2 ch (uart: 1 ch) m pd78064 16k-32k m pd78098b 40k-60k 2 ch 1 ch 1 ch 1 ch 8 ch - 2 ch 3 ch (uart: 1 ch) 69 pins 2.7 v o m pd78098 32k-60k m pd780973 24k-32k 3 ch 1 ch 1 ch 1 ch 5 ch - - 2 ch (uart: 1 ch) 56 pins 4.5 v - m pd78p0914 32k 6 ch - - 1 ch 8 ch - - 2 ch 54 pins 4.5 v o note 10-bit timer: 1 channel for control for inverter control for fip driving for lcd driving compatible with iebus for meter control for lv 3 ch (uart: 1 ch, time- multiplexing 3-wire: 1ch)
3 chapter 1 overview 1.2 78k/0 series features the 78k/0 series devices are 8-bit single-chip microcontrollers ideally suited for applications in the consumer field. the m PD78044F subseries are devices that implement high-speed, high-performance cpus and have on-chip peripheral hardware, such as rom, ram, i/o ports, timers, serial interfaces, a/d converter, fip controller/driver, 6-bit up/down counter, and interrupt controllers. the m pd78044h subseries of devices has been implemented by adding n-ch open-drain i/o pins to the m PD78044F subseries. the m pd780208 subseries has an enhanced version of the fip controller/driver of the m PD78044F subseries. the m pd780228 subseries has an enhanced version of the fip controller/driver of the m pd78044h subseries. the one-time prom or eprom versions or flash memory version, that can operate at the same low voltage as mask rom versions, such as the m pd78p048a, m pd78p048b, m pd78p0208, and m pd78f0228 are also provided. these products are well suited for fast shift to production of application systems and small-lot production. a block diagram and an overview of the functions of each subseries are shown on the following pages. * * *
4 78k/0 series application note figure 1-1. block diagram of the m PD78044F subseries to0/p30 ti0/intp0/p00 to1/p31 ti1/p33 to2/p32 ti2/p34 ci0/intp3/p03 si0/sb0/p25 so0/sb1/p26 sck0/p27 si1/p20 so1/p21 sck1/p22 stb/p23 busy/p24 ani0/p10- ani7/p17 av dd av ss av ref intp0/ti0/p00- intp3/ci0/p03 buz/p36 pcl/p35 16-bit timer/ event counter 8-bit timer/ event counter1 8-bit timer/ event counter2 watchdog timer watch timer 6-bit up/down counter serial interface 0 serial interface 1 a/d converter interrupt control buzzer output clock output control v dd v ss ic (v pp ) ram 78k/0 cpu core rom port0 port2 port3 port7 port8 port9 port10 port12 fip controller/ driver system control p00 p01-p03 p04 p10-p17 p20-p27 p30-p37 p70-p74 p80, p81 p90-p97 p100-p107 p110-p117 p120-p127 fip0-fip33 v load reset x1 x2 xt1/p04 xt2 port1 port11 remarks 1. the capacities of the internal rom and ram differ depending on the product. 2. the value enclosed in parentheses is applied to the m pd78p048a.
5 chapter 1 overview table 1-1. function overview of the m PD78044F subseries (1/2) product name m pd78042f m pd78043f m PD78044F m pd78045f m pd78p048a item rom masked rom one-time prom/eprom 16k bytes 24k bytes 32k bytes 40k bytes 60k bytes note 1 high-speed ram 512 bytes 1024 bytes 1024 bytes note 2 extended ram - 1024 bytes buffer ram 64 bytes fip display ram 48 bytes general-purpose registers 8 bits x 8 x 4 banks for main system clock 0.4 m s/0.8 m s/1.6 m s/3.2 m s/6.4 m s (at 5.0 mhz) for subsystem clock 122 m s (at 32.768 khz) instruction set ? 16-bit operations ? multiplication/division (8 bits x 8 bits, 16 bits/8 bits) ? bit (set, reset, test, boolean operations) ? bcd conversion, etc. i/o ports (including those ? total : 68 pins multiplexed with fip pins) ? cmos input : 2 pins ? cmos i/o : 27 pins ? n-ch open-drain i/o : 5 pins ? p-ch open-drain i/o : 16 pins ? p-ch open-drain output : 18 pins fip controller/driver ? total : 34 pins ? segments : 9 to 24 pins ? digits : 2 to 16 pins a/d converter ? 8-bit resolution x 8 channels ? power supply voltage: av dd = 4.0 to 6.0 v serial interface ? 3-wire serial i/o, sbi, or 2-wire serial i/o mode selectable : 1 channel ? 3-wire serial i/o mode (with automatic transmission/ reception function of up to 64 bytes) : 1 channel timer ? 16-bit timer/event counter : 1 channel ? 8-bit timer/event counter : 2 channels ? watch timer : 1 channel ? watchdog timer : 1 channel ? 6-bit up/down counter : 1 channel timer outputs 3 (one for 14-bit pwm output) notes 1. the memory size switching register (ims) can be used to select 16k, 24k, 32k, 40k, or 60k bytes. 2. the ims can be used to select 512k or 1024k bytes. minimum instruction execution time internal memory *
6 78k/0 series application note table 1-1. function overview of the m PD78044F subseries (2/2) product name m pd78042f m pd78043f m PD78044F m pd78045f m pd78p048a item clock output 19.5 khz, 39.1 khz, 78.1 khz, 156 khz, 313 khz, 625 khz (at main system clock of 5.0 mhz) 32.768 khz (at subsystem clock of 32.768 khz) buzzer output 1.2 khz, 2.4 khz, 4.9 khz (at 5.0 mhz: main system clock) maskable internal: 10, external: 4 non-maskable internal: 1 software 1 test input internal: 1 power supply voltage v dd = 2.7 to 6.0 v package ? 80-pin plastic qfp (14 x 20 mm) ? 80-pin ceramic wqfn: only for the m pd78p048a vectored interrupt factors
7 chapter 1 overview figure 1-2. block diagram of the m pd78044h subseries to0/p30 ti0/intp0/p00 to1/p31 ti1/p33 to2/p32 ti2/p34 ci0/intp3/p03 si0/sb0/p25 so0/sb1/p26 sck0/p27 si1/p20 so1/p21 sck1/p22 stb note /p23 busy note /p24 ani0/p10- ani7/p17 av dd av ss av ref intp0/ti0/p00- intp3/ci0/p03 buz/p36 pcl/p35 16-bit timer/ event counter 8-bit timer/ event counter1 8-bit timer/ event counter2 watchdog timer watch timer 6-bit up/down counter note serial interface 0 note serial interface 1 a/d converter interrupt control buzzer output clock output control v dd v ss ic (v pp ) ram 78k/0 cpu core rom port0 port2 port3 port7 port8 port9 port10 port12 fip controller/ driver system control p00 p01-p03 p04 p10-p17 p20-p27 p30-p37 p70-p74 p80, p81 p90-p97 p100-p107 p110-p117 p120-p127 fip0-fip33 v load reset x1 x2 xt1/p04 xt2 port1 port11 note only for the m pd78p048b remarks 1. the capacities of the internal rom and ram differ depending on the product. 2. the value enclosed in parentheses is applied to the m pd78p048b. *
8 78k/0 series application note table 1-2. function overview of the m pd78044h subseries (1/2) product name m pd78044h m pd78045h m pd78046h m pd78p048b note 1 item rom masked rom one-time prom/eprom 32k bytes 40k bytes 48k bytes 60k bytes note 2 high-speed ram 1024 bytes extended ram - 1024 bytes note 3 buffer ram - 64 bytes fip display ram 48 bytes general-purpose register 8 bits x 8 x 4 banks for main system clock 0.4 m s/0.8 m s/1.6 m s/3.2 m s/6.4 m s (at 5.0 mhz) for subsystem clock 122 m s (at 32.768 khz) instruction set ? 16-bit operations ? multiplication/division (8 bits x 8 bits, 16 bits/8 bits) ? bit manipulations (set, reset, test, boolean operations) ? bcd conversion, etc. i/o ? total : 68 lines ports (including those multiplexed with fip pins) ? cmos input : 2 lines ? cmos i/o : 19 lines ? n-ch open-drain i/o : 13 lines ? p-ch open-drain i/o : 16 lines ? p-ch open-drain output : 18 lines fip controller/driver ? total : 34 lines ? segments: 9 to 24 lines ? digits : 2 to 16 lines a/d converter ? 8-bit resolution x 8 channels ? 8-bit resolution x 8 channels ? power supply voltage: av dd = 4.0 to 5.5 v ? power supply voltage: av dd = 4.0 to 6.0 v serial interface ? 3-wire serial i/o mode: 1 channel ? 3-wire serial i/o, sbi, or 2-wire serial i/o mode: 1 channel ? 3-wire serial i/o mode with automatic transmission/reception function: 1 channel notes 1. under development 2. the memory size switching register (ims) can be used to select 32k, 40k, 48k, or 60k bytes. 3. the internal extended ram size switching register (ixs) can be used to select 0 or 1024 bytes. internal memory minimum instruction execution time *
9 chapter 1 overview table 1-2. function overview of the m pd78044h subseries (2/2) product name m pd78044h m pd78045h m pd78046h m pd78p048b note item timer ? 16-bit timer/event counter : 1 channel ? 16-bit timer/event counter: ? 8-bit timer/event counter : 2 channels 1 channel ? watch timer : 1 channel ? 8-bit timer/event counter: ? watchdog timer : 1 channel 2 channels ? watch timer: 1 channel ? watchdog timer: 1 channel ? 6-bit up/down counter: 1 channel timer outputs 3 lines (one for 14-bit pwm output) clock output 19.5 khz, 39.1 khz, 78.1 khz, 156 khz, 313 khz, 625 khz (at main system clock of 5.0 mhz) 32.768 khz (at subsystem clock of 32.768 khz) buzzer output 1.2 khz, 2.4 khz, 4.9 khz (at main system clock of 5.0 mhz) maskable internal: 8, external: 4 internal: 10, external: 4 non-maskable internal: 1 software 1 test input internal: 1 power supply voltage v dd = 2.7 to 5.5 v v dd = 2.7 to 6.0 v package ? 80-pin plastic qfp (14 x 20 mm) ? 80-pin plastic qfp (14 x 20 mm) ? 80-pin ceramic wqfn note under development vectored interrupt factors
10 78k/0 series application note figure 1-3. block diagram of the m pd780208 subseries to0/p30 ti0/intp0/p00 to1/p31 ti1/p33 to2/p32 ti2/p34 si0/sb0/p25 so0/sb1/p26 sck0/p27 si1/p20 so1/p21 sck1/p22 stb/p23 busy/p24 ani0/p10- ani7/p17 av dd av ss av ref intp0/ti0/p00- intp3/p03 buz/p36 pcl/p35 16-bit timer/ event counter 8-bit timer/ event counter1 8-bit timer/ event counter2 watchdog timer watch timer serial interface 0 serial interface 1 a/d converter interrupt control buzzer output clock output control v dd v ss ic (v pp ) ram 78k/0 cpu core rom port0 port2 port3 port7 port8 port9 port10 port12 fip controller/ driver system control p00 p01-p03 p04 p10-p17 p20-p27 p30-p37 p70-p74 p80-p87 p90-p97 p100-p107 p110-p117 p120-p127 fip0-fip52 v load reset x1 x2 xt1/p04 xt2 port1 port11 remark 1. the capacities of the internal rom and ram differ depending on the product. 2. the value enclosed in parentheses is applied to the m pd78p0208.
11 chapter 1 overview table 1-3. function overview of the m pd780208 subseries (1/2) product name m pd780204 m pd780205 m pd780206 m pd780208 m pd78p0208 item rom masked rom one-time prom/eprom 32k bytes 40k bytes 48k bytes 60k bytes 60k bytes note 1 high-speed ram 1024 bytes extended ram - 1024 bytes 1024 bytes note 2 buffer ram 64 bytes fip display ram 80 bytes general-purpose registers 8 bits x 8 x 4 banks for main system clock 0.4 m s/0.8 m s/1.6 m s/3.2 m s/6.4 m s (at 5.0 mhz) for subsystem clock 122 m s (at 32.768 khz) instruction set ? 16-bit operations ? multiplication/division (8 bits x 8 bits, 16 bits/8 bits) ? bit (set, reset, test, boolean operations) ? bcd conversion, etc. i/o ports (including those ? total : 74 pins multiplexed with fip pins) ? cmos input : 2 pins ? cmos i/o : 27 pins ? n-ch open-drain i/o : 5 pins ? p-ch open-drain i/o : 24 pins ? p-ch open-drain output : 16 pins fip controller/driver ? total : 53 pins ? segments : 9 to 40 pins ? digits : 2 to 16 pins a/d converter ? 8-bit resolution x 8 channels ? power supply voltage: av dd = 4.0 to 5.5 v serial interface ? 3-wire serial i/o, sbi, or 2-wire serial i/o mode selectable : 1 channel ? 3-wire mode (with automatic transmission/ reception function of up to 64 bytes) : 1 channel timer ? 16-bit timer/event counter : 1 channel ? 8-bit timer/event counter : 2 channels ? watch timer : 1 channel ? watchdog timer : 1 channel timer outputs 3 (one for 14-bit pwm output) notes 1. the memory size switching register (ims) can be used to select 32k, 40k, 48k, or 60k bytes. 2. the internal extended ram size switching register (ixs) can be used to select either 0 or 1024 bytes. internal memory minimum instruction execution time *
12 78k/0 series application note table 1-3. function overview of the m pd780208 subseries (2/2) product name m pd780204 m pd780205 m pd780206 m pd780208 m pd78p0208 item clock output 19.5 khz, 39.1 khz, 78.1 khz, 156 khz, 313 khz, 625 khz (at main system clock of 5.0 mhz) 32.768 khz (at subsystem clock of 32.768 khz) buzzer output 1.2 khz, 2.4 khz, 4.9 khz (at 5.0 mhz: main system clock) maskable internal: 9, external: 4 non-maskable internal: 1 software 1 text input internal: 1 power supply voltage v dd = 2.7 to 5.5 v package ? 100-pin plastic qfp (14 x 20 mm) ? 100-pin ceramic wqfn: only for the m pd78p0208 vectored interrupt factors
13 chapter 1 overview figure 1-4. block diagram of the m pd780228 subseries port0 p00, p01 p20-p25 port1 port2 port4 port5 port6 port7 port8 port9 port10 fip controller/ driver system control ti1/p23 tio50/p24 sck/p20 so/p21 si/p22 av dd ani0/p10- ani7/p17 av ss intp0/p00 intp1/p01 8-bit remote controller timer (tm1) 8-bit pwm timer (tm50) 78k/0 cpu core rom flash memory ram 1024 bytes v dd0 , v dd1 , v dd2 8-bit pwm timer (tm51) serial interface (sio3) a/d converter (a/d1) interrupt control (int) watchdog timer p40-p47 tio51/p25 p50-p57 p60-p67 p70-p77 p80-p87 p90-p97 p100-p107 fip0-fip47 v load reset x1 x2 p10-p17 v ss0 , v ss1 ic (v pp ) remarks 1. the internal rom capacity differs depending on the product. 2. the value in parentheses applies to the m pd78f0228 only. *
14 78k/0 series application note table 1-4. function overview of the m pd780228 subseries product name m pd780226 m pd780228 m pd78f0228 item rom masked rom flash memory 48k bytes 60k bytes 60k bytes note high-speed ram 1024 bytes extended ram 512 bytes fip display ram 96 bytes general-purpose registers 8 bits x 8 x 4 banks minimum instruction execution time 0.4 m s/0.8 m s/1.6 m s/3.2 m s/6.4 m s (at main system clock of 5.0 mhz) instruction set ? 16-bit operations ? multiplication/division (8 bits x 8 bits, 16 bits/8 bits) ? bit (set, reset, test, boolean operations) ? bcd conversion, etc. i/o ports (including those ? total : 72 pins multiplexed with fip pins) ? cmos input : 8 pins ? cmos i/o : 16 pins ? n-ch open-drain i/o : 16 pins ? p-ch open-drain i/o : 24 pins ? p-ch open-drain output : 8 pins fip controller/driver ? total : 48 pins ? 10-ma display current : 16 pins ? 3-ma display current : 32 pins a/d converter ? 8-bit resolution x 8 channels ? power supply voltage: av dd = 4.5 to 5.5 v serial interface ? 3-wire serial i/o mode: 1 channel timer ? 8-bit remote controller timer : 1 channel ? 8-bit pwm timer : 2 channels ? watchdog timer : 1 channel timer outputs 2 (8-bit pwm output enabled) maskable internal: 6, external: 4 non-maskable internal: 1 software 1 power supply voltage v dd = 4.5 to 5.5 v package 100-pin plastic qfp (14 x 20 mm) note the memory size switching register (ims) can be used to select 48k or 60k bytes. caution the m pd780228 subseries is under development. internal memory vectored interrupt factors *
15 chapter 2 software basics chapter 2 software basics 2.1 data transfer the addresses set in the de and hl registers are the first addresses used in data exchange. the number of bytes in the data exchange is specified in the b register. figure 2-1. data exchange de+b? de hl+b? hl address address data exchange (1) registers used a, b, de, hl (2) program listing exch: mov a,[de] xch a,[hl] xch a,[de] incw de incw hl dbnz b,$exch ret
16 78k/0 series application note 2.2 data comparison the addresses set in the de and hl registers are the first addresses used in data comparison. the number of bytes in the data comparison is specified in the b register. when the comparison result is equal, the cy flag is set to 0. when the result is not equal, cy is set to 1. after the flag setting, processing is returned to the main program. figure 2-2. data comparison de+b? de hl+b? hl address address data comparison (1) registers used a, b, de, hl (2) program listing comp: mov a,[de] cmp a,[hl] bnz $error incw de incw hl dbnz b,$comp clr1 cy br rtn error: set1 cy rtn: ret
17 chapter 2 software basics 2.3 decimal addition the lowest addresses for decimal addition are specified in the de and hl registers. the number of digits specified in bytnum are added. the addition result is saved in the area pointed to by the hl register. when the addition result is an overflow or an underflow, the processing branches to error processing. have the branch address defined as error in main program and make it a public declaration. figure 2-3. decimal addition de hl+ bytnum? hl hl hl+ bytnum? de+ bytnum? += address address address (1) flowchart bcdadd c number of bytes in the decimal addition b c? number of bytes in the decimal addition not including the sign do the augend and the addend have the same signs? no yes decimal addition ret decimal subtraction bcdad2
18 78k/0 series application note dadds cy 0 sign flag sflag 0 dadds1 a [de]+[hl]+cy add both the addend and augend to cy. de de+1, hl hl+1 increment the addend and augend addresses. b b? b=0 no yes a [de]+[hl]+cy add both the addend and augend to cy. cy=1 yes no sign flag sflag 1 cy=0 dadds3 decimal-adjust the result. cy=1 a7=1 no yes no yes yes no sign flag sflag=1 a7 1 dadds6 save a in memory ret error the result is decimal-adjusted and saved in memory.
19 chapter 2 software basics dsubs1 ret dsubs make the subtrahend positive. sign flag 0 minuend<0 yes no make the subtrahend positive. sign flag 1 dsubs2 b c, cy 0 a [de] ?[hl] ?cy subtract cy from the minuend minus the subtrahend. de de+1, hl hl+1 increment the minuend and subtrahend addresses c c? c=0 the result is decimal-adjusted and saved in memory. no yes cy=1 invert the sign flag by taking the 10's complement. result=0 yes no no yes dsubs5 yes no sign flag=1 assign a negative sign to the result.
20 78k/0 series application note (2) registers used ax, bc, de, hl (3) program listing ;************************************************************ ; * ; input parameters * ; hl register: start address of the addend * ; de register: start address of the augend * ; output parameters * ; hl register: start address of the operation result * ; * ;************************************************************ public bcdadd,bcdad1,bcdad2 public dadds public dsubs extrn error ; branch address for error processing extbit sflag ; sign flag ; bytnum equ 4 ; set the number of operand digits ; cseg bcdadd: mov c,#bytnum ; set the number of operand digits in the c register. bcdad1: mov a,c mov b,a dec b bcdad2: mov a,[hl+bytnum-1] ; read in the most significant bit (sign data) of the augend xchw ax,de xchw ax,hl xchw ax,de xor a,[hl+bytnum-1] ; read in the most significant bit (sign data) of the augend xchw ax,hl xchw ax,de xchw ax,hl bt a.7,$bcdad3 ; do the signs agree? else subtraction processing call !dadds ; then addition processing ret bcdad3: call !dsubs ret
21 chapter 2 software basics ;=========================================================== ; ***** decimal addition ***** ;=========================================================== dadds: clr1 cy clr1 sflag dadds1: mov a,[de] ; start addition from the least significant digit addc a,[hl] adjba mov [hl],a incw hl incw de dbnz b,$dadds1 ; end addition of (number-of-operand-digits C 1) mov a,[de] addc a,[hl] dadds2: bnc $dadds3 ; negative addition set1 sflag ; then set in the negative state clr1 cy dadds3: adjba bnc $dadds4 br error dadds4: bf a.7,$dadds5 br error dadds5: bf sflag,$dadds6 ; set sign set1 a.7 dadds6: mov [hl],a ret
22 78k/0 series application note ;================================================================= ; ***** decimal subtraction ***** ;================================================================= dsubs: push hl clr1 sflag mov a,[hl+bytnum-1] ; set the subtrahend to positive value. clr1 a.7 mov [hl+bytnum-1],a xchw ax,de xchw ax,hl xchw ax,de mov a,[hl+bytnum-1] bf a.7,$dsubs1 ; the minuend is negative. clr1 a.7 ; then set the minuend to a positive value. mov [hl+bytnum-1],a set1 sflag ; set the sign to negative. dsubs1: xchw ax,hl xchw ax,de xchw ax,hl mov a,c mov b,a clr1 cy dsubs2: mov a,[de] subc a,[hl] adjbs mov [hl],a incw hl incw de dbnz c,$dsubs2 ; end of the subtraction of the number of operand digits. bnc $dsubs5 ; then subtrahend > minuend pop hl push hl mov a,b mov c,a dsubs3: mov a,#99h ; complement operation on the subtraction result sub a,[hl] ; (subtraction-result C 99h) adjbs mov [hl],a incw hl dbnz c,$dsubs3 pop hl push hl set1 cy mov a,b mov c,a
23 chapter 2 software basics dsubs4: mov a,#0 ; add 1 to the complement operation result. addc a,[hl] adjba mov [hl],a incw hl dbnz c,$dsubs4 mov1 cy,sflag not1 cy mov1 sflag,cy ;==================================================== ; ***** 0 check of operation result ***** ;==================================================== dsubs5: mov a,b mov c,a pop hl push hl mov a,#0 dsubs6: cmp a,[hl] ; 0 check from the low-order digit incw hl bnz $dsubs7 dbnz c,$dsubs6 ; end of checking all digits for 0 pop hl ; then subtraction result = 0 ret dsubs7: bf sflag,$dsubs8 ; subtraction result is negative. pop hl ; then set sign push hl mov a,[hl+bytnum-1] set1 a.7 mov [hl+bytnum-1],a dsubs8: pop hl ret
24 78k/0 series application note 2.4 decimal subtraction the lowest addresses for decimal subtraction are set in the de and hl registers. subtraction is performed on the number of digits specified in bytnum. the subtraction result is saved in the area specified in the hl register. additionally, when the subtraction result is an overflow or an underflow, the processing branches to error processing. have the branch address defined as error in main program and make it a public declaration. this program replaces the augend and addend with the minuend and subtrahend respectively, and calls the decimal addition program. figure 2-4. decimal subtraction de hl bytnum? hl hl hl+ bytnum? de+ bytnum? ? address address address (1) flowchart bcdsub c number of bytes in the decimal subtraction the subtrahend and minuend act as the addend and augend in decimal addition. ret invert the sign bit of the subtrahend. (2) registers used ax, bc, de, hl
25 chapter 2 software basics (3) program listing ;************************************************************ ; input parameters * ; hl register: start address of the subtrahend * ; de register: start address of the minuend * ; output parameters * ; hl register: start address of the operation result * ; * ;************************************************************ public bytnum public bcdsub extrn bcdadd,bcdad2 ; bytnum equ 4 ; set the number of operand digits ; cseg bcdsub: mov c,#bytnum ; set the number of operand digits in the c register. bcdsu1: mov a,c mov b,a dec b mov a,[hl+bytnum-1] ; set the most significant bit (sign data) of the subtrahend for use in addition. mov1 cy,a.7 ; invert the sign data. not1 cy mov1 a.7,cy mov [hl+bytnum-1].a call !bcdad2 ; call decimal addition processing. ret
26 78k/0 series application note 2.5 binary-to-decimal conversion 16-bit binary data in the data memory is converted into 5-digit decimal data and saved in the data memory. the 16-bit binary data are divided by the decimal number 10 (4 times) and the conversion is based on the values of the results and remainders of these operations. figure 2-5. binary-to-decimal conversion xxxx 0x0x0x0x0x low high low high 16-bit binary (2 bytes) 5-digit decimal (5 bytes) example ffh is converted into decimal. ff00 0505020000 low high low high 16-bit binary (2 bytes) 5-digit decimal (5 bytes) (1) registers used ax, bc, hl
27 chapter 2 software basics (2) program listing public b_dconv datdec equ 10 dseg saddrp rega: ds 2 ; save 16-bit binary data. regb: ds 5 ; save 5-digit decimal data. column equ 4 b_dconv: movw ax,rega mov b,#colnum movw hl,#regb b_d1: mov c,#datdec divuw c xch a,c mov [hl],a incw hl xch a,c dbnz b,$b_d1 mov a,x mov [hl],a ret
28 78k/0 series application note 2.6 bit operation manipulation instruction the logical product (and) of the 1-bit flag in data memory and bit 4 in port 6 is taken. the logical sum (or) of the result and bit 5 of port 6 is output to bit 6 of port 6. figure 2-6. bit operation flg port6.4 port6.5 port6.6 (1) program listing public bit_op,flg bseg flg dbit bit_op: mov1 cy,flg and1 cy,p6.4 or1 cy,p6.5 mov1 p6.6,cy ret
29 chapter 2 software basics 2.7 binary multiplication (16 bits x 16 bits) the data in the multiplicand area (hikake; 16 bits) and the multiplier area (kake; 16 bits) are multiplied. the result is saved in the operation result storage area (kotae). figure 2-7. binary multiplication hikake + 1 hikake kake + 1 kake kotae + 3 kotae x operation result storage area (4 bytes) multiplier area (2 bytes) multiplicand area (2 bytes) = multiplication is implemented by adding the multiplicand only the number of 1 bits in the multiplier.
30 78k/0 series application note set the data in the multiplicand area (hikake) and the multiplier area (kake), and then call the subroutine s_kakeru. extrn s_kakeru extrn hikake,kake,kotae main: ; multiplier . . hikake=worka (a) ; multiplicand data save in the multiplicand area hikake+1=worka+1 (a) ; kake=workb (a) ; multiplier data save in the multiplier area kake+1=workb+1 (a) ; call !s_kakeru ; multiplication routine call hl=#kotae ; hl <- ram address of the operation result storage area . ; stores the result by the indirect address transfer . . caution manipulate data memory in 8-bit units.
31 chapter 2 software basics (1) i/o conditions ? input parameters hikake : save the multiplicand data. kake : save the multiplier data. ? output parameter kotae : saves the operation result. (2) spd chart [multiplication subroutine] initialization of the operation result storage area work1<-multiplier (low order) for (b=#0 ; b<#16 ; b++) s_kakeru then work1<-multiplier (high order) if (b = #8) shift work1 one bit to the left. if_bit (cy = #1) then add the multiplicand to the operation result storage area. then shift the operation result storage area one bit to the left. if (b #15) (3) registers used a, b
32 78k/0 series application note (4) program listing $pc(044a) ; public hikake,s_kakeru,kake,kotae ; ;***************************************** ; ram definition ;***************************************** dseg saddr hikake: ds 2 ; multiplicand area kake: ds 2 ; multiplier area work1: ds 1 ; work area kotae: ds 4 ; operation result storage area ; ;***************************************** ; multiplication ;***************************************** cseg ; s_kakeru: ; work1=kake+1 (a) ; save multiplier (low order) in the work area. kotae=#0 ; initialize the operation result storage area. kotae+1=#0 ; kotae+2=#0 ; kotae+3=#0 ; for(b=#0;b<#16;b++) (a) ; if at the end of the low-order multiplier, if(b == #8) (a) ; save the high-order multiplier in the work area. work1=kake (a) ; endif ; a=work1 ; shift the multiplier one bit to the left. clr1 cy ; rolc a,1 ; work1=a ; if_bit (cy) ; if carry, kotae+=hikake (a) ; add the multiplicand to the operation result (kotae+1)+=hikake+1,cy (a) ; storage area. (kotae+2)+=#0,cy (a) ; (kotae+3)+=#0,cy (a) ; endif ; if(b != #15) (a) ; kotae+=kotae (a) ; shift the operation result storage area one bit to kotae+1+=kotae+1,cy (a) ; the left. kotae+2+=kotae+2,cy (a) ; kotae+3+=kotae+3,cy (a) ; endif ; next ; ret ; end ;
33 chapter 2 software basics 2.8 binary division (32 bits/16 bits) the dividend area (hiwaru; 32 bits) is divided by the divisor area (warum; 16 bits) and the result is saved in the operation result storage area (kotae). if there is a remainder, it is saved in the calculation result remainder storage area (amari). when the divisor is 0, an error results. figure 2-8. binary division warum + 1 warum kotae + 3 amari operation result storage area (4 bytes) divisor area (2 bytes) dividend storage area (4 bytes) hiwaru + 3 hiwaru amari + 1 kotae calculation result remainder storage area (2 bytes) = the dividend is shifted left starting from the high-order digit into the work area. if the contents of the work area is greater than the divisor, the divisor is subtracted from the work area, and 1 is set in the least significant bit of the dividend. in the above method, division is implemented by operating only on the number of bits in the dividend. when the divisor is 0, the error flag (f_err) is set.
34 78k/0 series application note set data in the dividend area (hiwaru) and divisor area (warum), and then call the s_waru subroutine. extrn s_waru extrn hiwaru,warum,kotae exbit f_err main: . ; . ; hiwaru=worka (a) ; save the dividend data in the dividend area hiwaru+1=worka+1 (a) ; warum=workb (a) ; save divisor data in the divisor area warum+1=workb+1 (a) ; call !s_waru ; division routine call hl=#kotae ; hl <- save the ram address of the operation result . ; storage area . ; if_bit(f_err) ; calculation error processing ; endif ; . . . caution manipulate data memory in 8-bit units.
35 chapter 2 software basics (1) i/o conditions ? input parameters hiwaru : save the dividend data. warum : save the divisor data. ? output parameters kotae : save the calculation result. (2) spd chart [division subroutine] clear operation error flag s_waru then set operation error flag then for (b=#0 ; b<#32 ; b++) simultaneously shift the dividend and calculation result remainder one bit to the left. then calculation result remainder<-calculation result remainder - divisor dividend<-dividend or #1 operation-result-storage-area<-dividend-area initialize the operation result storage area and calculation result remainder storage srea. if (divisor = #0) if (calculation-result-remainder > divisor) if_bit (opeartion-error-falg = #0) (3) registers used a, b
36 78k/0 series application note (4) program listing $pc(044a) ; public s_waru,hiwaru,warum,f_err extrn kotae ; ;****************************************** ; ram definition ;****************************************** dseg saddr hiwaru: ds 4 ; dividend area warum: ds 2 ; divisor area amari: ds 2 ; calculation result remainder storage area bseg f_err dbit ; operation error flag ;****************************************** ; division ;****************************************** cseg ; s_waru: ; clr1 f_err ; clear operation error flag amari=#0 ; clear the calculation result remainder storage area amari+1=#0 ; to zero kotae=#0 ; clear the operation result storage area to zero kotae+1=#0 ; kotae+2=#0 ; kotae+3=#0 ; if(warum == #0) ; divisor = 0? if(warum+1 == #0) ; set1 f_err ; if the divisor is 0, set the operation error flag. endif ; endif ; if_bit(!f_err) ; operation error? for(b=#0;b < #32;b++) (a) ; start the 32-bit division. hiwaru+=hiwaru (a) ; shift the dividend and the remainder one bit to the left. hiwaru+1+=hiwaru+1,cy (a) ; hiwaru+2+=hiwaru+2,cy (a) ; hiwaru+3+=hiwaru+3,cy (a) ; amari+=amari,cy (a) ; amari+1+=amari+1,cy (a) ; ; if(amari+1 > warum+1) (a) ; remainder divisor? amari-=warum (a) ; remainder = remainder C divisor amari+1-=warum+1,cy (a) ; hiwaru |= #1 ; save 1 in the first bit of the dividend area. elseif_bit(z) ; if(amari >= warum) (a) ; amari-=warum(a) ; amari+1-=warum+1,cy (a) ; hiwaru |= #1 ; endif ; endif ; next ; kotae=hiwaru (a) ; save the operation result. kotae+1=hiwaru+1 (a) ; kotae+2=hiwaru+2 (a) ; kotae+3=hiwaru+3 (a) ; endif ; ret ; end
37 chapter 3 system clock switching application chapter 3 system clock switching application the 78k/0 series can control the selection of the cpu clock and oscillator operation by rewriting the processor clock control register (pcc). the display mode registers 0 and 1 (dspm0, dspm1) can be used to set mode of the noise eliminator for the subsystem clock and enable or disable display operation (except for the m pd780228 subseries). when the cpu clock is changed, it takes the time shown in tables 3-1 and 3-2 from when a rewrite instruction is used to the pcc until the cpu clock is actually changed. for a while after an instruction to rewrite the pcc is issued, therefore, it cannot be determined which clock, old or new, is used by the cpu. when a main system clock is to be stopped or a stop instruction is to be executed, a wait enough to assure instructions listed in tables 3-1 and 3-2 have been executed is needed. table 3-1. maximum time required to change the cpu clock ( m PD78044F, m pd78044h, and m pd780208 subseries) caution selecting of the frequency division of the cpu clock (pcc0-pcc2) and switching from main system clock to subsystem clock (css: 0 -> 1) must not be performed simultane- ously. however, selecting of the frequency division of the cpu clock (pcc0-pcc2) and switching from subsystem clock to main system clock (css: 1 -> 0) can be performed simultane- ously. remarks 1. the execution time of one instruction is the minimum instruction execution time of the cpu clock before switching. 2. time enclosed in parentheses is required when f x = 5.0 mhz and f xt = 32.768 khz. css pcc2 pcc1 pcc0 css 0 pcc2 0 pcc1 0 pcc0 0 css 0 pcc2 0 pcc1 0 pcc0 1 css 0 pcc2 0 pcc1 1 pcc0 0 css 0 pcc2 0 pcc1 1 pcc0 1 css 0 pcc2 1 pcc1 0 pcc0 0 css 1 pcc2 x pcc1 x pcc0 x setting before switching setting after switching 0000 16 instructions 16 instructions 16 instructions 16 instructions f x /2f xt instructions (64) 0 0 1 8 instructions 8 instructions 8 instructions 8 instructions f x /4f xt instructions (32) 0 1 0 4 instructions 4 instructions 4 instructions 4 instructions f x /8f xt instructions (16) 0 1 1 2 instructions 2 instructions 2 instructions 2 instructions f x /16f xt instructions (8) 1 0 0 1 instruction 1 instruction 1 instruction 1 instruction f x /32f xt instructions (4) 1 x x x 1 instruction 1 instruction 1 instruction 1 instruction 1 instruction
38 78k/0 series application note table 3-2. maximum time required to change the cpu clock ( m pd780228 subseries) setting before switching setting after switching pcc2 pcc1 0 0 8 instructions 8 instructions 8 instructions 8 instructions pcc0 pcc2 pcc1 pcc0 00 0 pcc2 pcc1 pcc0 00 1 pcc2 pcc1 pcc0 01 0 pcc2 pcc1 pcc0 01 1 pcc2 pcc1 pcc0 10 0 1 0 0 16 instructions 16 instructions 16 instructions 16 instructions 0 0 1 4 instructions 4 instructions 4 instructions 4 instructions 0 0 1 2 instructions 2 instructions 2 instructions 2 instructions 1 1 0 1 instruction 1 instruction 1 instruction 1 instruction 0 remark the execution time of one instruction is the minimum instruction execution time of the cpu clock before switching. *
39 chapter 3 system clock switching application figure 3-1. format of the processor clock control register ( m PD78044F, m pd78044h, and m pd780208 subseries) r/w css pcc2 pcc1 pcc0 cpu clock (f cpu ) selection note 2 0000f x 001f x /2 010f x /2 2 011f x /2 3 100f x /2 4 1000f xt /2 001 010 011 100 other than the above setting prohibited r cls cpu clock status 0 main system clock 1 subsystem clock r/w frc selection of the feedback resistor of the subsystem clock 0 use on-chip feedback resistor. 1 do not use on-chip feedback resistor. r/w mcc control of the main system clocks oscillation note 3 0 oscillation possible 1 oscillation stop notes 1. bit 5 is read-only. 2. in the m PD78044F and m pd78044h subseries, fip display is possible only when css is 0 and pcc2-pcc0 is 000 or 001. 3. when the cpu is operating under the subsystem clock, use mcc to stop the oscillation of the main system clock. do not use the stop instruction. caution always set 0 in bit 3. remarks 1. f x : oscillation frequency of the main system clock 2. f xt : oscillation frequency of the subsystem clock 7 mcc symbol pcc address fffbh at reset 04h r/w r/w note 1 6 frc 5 cls 4 css 3 0 2 pcc2 1 pcc1 0 pcc0
40 78k/0 series application note figure 3-2. format of the processor clock control register ( m pd780228 subseries) 7 0 symbol pcc address fffbh at reset 04h r/w r/w 6 0 5 0 pcc2 pcc1 pcc0 cpu clock (f cpu ) selection 000f x 001f x /2 010f x /2 2 011f x /2 3 100f x /2 4 other than the above setting prohibited 4 0 3 0 2 pcc2 1 pcc1 0 pcc0 caution always set 0 in bits 3 to 7. remark f x : oscillation frequency of the main system clock of the instructions for the m PD78044F, m pd78044h, m pd780208, and m pd780228 subseries, the fastest requires two cpu clocks. thus, the relationship between the cpu clock (f cpu ) and minimum instruction execution time is as shown in table 3-3. table 3-3. relationship between the cpu clock and minimum instruction execution time cpu clock (f cpu ) minimum instruction execution time: 2/f cpu f x 0.4 m s f x /2 0.8 m s f x /2 2 1.6 m s f x /2 3 3.2 m s f x /2 4 6.4 m s f xt note 122 m s note only for the m PD78044F, m pd78044h, and m pd780208 subseries remark f x = 5.0 mhz, f xt = 32.768 khz f x : oscillation frequency of the main system clock f xt : oscillation frequency of the subsystem clock * *
41 chapter 3 system clock switching application figure 3-3. format of the display mode register 0 ( m PD78044F and m pd78044h subseries) timing status ksf 7 dspm06 6 0 5 0 4 segs3 3 segs2 2 segs1 1 segs0 0 segs3 segs2 segs1 segs0 number of display segments 00009 000110 001011 001112 010013 010114 011015 011116 100017 100118 101019 101120 110021 110122 111023 111124 dspm06 mode setting for the noise eliminator of the subsystem clock note 2 0 2.5 mhz < f x 5.0 mhz 1 1.25 mhz < f x 2.5 mhz ksf 0 display timing 1 key scan timing dspm0 symbol ffa0h address 00h at reset r/w note 1 r/w < < notes 1. bit 7 (ksf) is read-only. 2. specify a value in accordance with the oscillation frequency of the main system clock (f x ). the noise eliminator can be used during fip display operation. remark f x : oscillation frequency of the main system clock
42 78k/0 series application note figure 3-4. format of the display mode register 0 ( m pd780208 subseries) (1/2) ksf 7 dspm06 6 dspm05 5 segs4 4 segs3 3 segs2 2 segs1 1 segs0 0 dspm0 symbol ffa0h address 00h at reset r/w r/w segs3 segs2 segs1 segs0 number of display segments (display mode 1) 00009 000110 001011 001112 010013 010114 011015 011116 100017 100118 101019 101120 110021 110122 111023 111124 number of display outputs (display mode 2) 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 000025 25 000126 26 001027 27 001128 28 010029 29 010130 30 011031 31 011132 32 100033 33 100134 34 101035 35 101136 36 110037 37 110138 note 38 111039 note 39 1 segs4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11140 note 40 r/w note if the total number of digits and segments exceeds 53, digits have precedence over segments.
43 chapter 3 system clock switching application figure 3-4. format of the display mode register 0 ( m pd780208 subseries) (2/2) ksf 7 dspm06 6 dspm05 5 segs4 4 segs3 3 segs2 2 segs1 1 segs0 0 ksf timing status 0 display timing 1 key scan timing dspm0 symbol ffa0h address 00h at reset r/w note 1 r/w r dspm06 mode setting for the noise eliminator of the subsystem clock note 2 0 2.5 mhz < f x 5.0 mhz 1 1.25 mhz < f x 2.5 mhz note 3 r/w dspm05 setting of display mode 0 display mode 1 (segment/character type) 1 display mode 2 (type that a segment extends two or more grids) r/w < < notes 1. bit 7 (ksf) is read-only. 2. specify a value in accordance with the oscillation frequency of the main system clock (f x ). the noise eliminator can be used during fip display operation. 3. when f x is used from above 1.25 mhz to 2.5 mhz, set 1 in dspm06 before fip display. remark f x : oscillation frequency of the main system clock
44 78k/0 series application note figure 3-5. format of the display mode register 1 ( m PD78044F and m pd78044h subseries) digs3 7 digs2 6 digs1 5 digs0 4 dims3 3 dims2 2 dims1 1 dims0 0 dims0 display cycle selection 0 1024/f x as 1 display cycle (one display cycle is 204.8 s at 5.0 mhz.) 1 2048/f x as 1 display cycle (one display cycle is 409.6 s at 5.0 mhz.) dspm1 symbol ffa1h address 00h at reset r/w r/w dims3 dims2 dims1 cut width of the digit signal 0 0 0 1/16 0 0 1 2/16 0 1 0 4/16 0 1 1 6/16 1 0 0 8/16 1 0 1 10/16 1 1 0 12/16 1 1 1 14/16 digs3 digs2 digs1 digs0 number of display digits 0000 display stop (static display) note 00012 00103 00114 01005 01016 01107 01118 10009 100110 101011 101112 110013 110114 111015 111116 note when display is disabled, a port output latch can be operated to enable static display. remark f x : oscillation frequency of the main system clock
45 chapter 3 system clock switching application figure 3-6. format of the display mode register 1 ( m pd780208 subseries) digs3 7 digs2 6 digs1 5 digs0 4 dims3 3 dims2 2 dims1 1 dims0 0 dims0 setting of display mode cycle 0 1024/f x as 1 display cycle (one display cycle is 204.8 s at 5.0 mhz.) 1 2048/f x as 1 display cycle (one display cycle is 409.6 s at 5.0 mhz.) dspm1 symbol ffa1h address 00h at reset r/w r/w dims3 dims2 dims1 cut width of the fip output signal 0 0 0 1/16 0 0 1 2/16 0 1 0 4/16 0 1 1 6/16 1 0 0 8/16 1 0 1 10/16 1 1 0 12/16 1 1 1 14/16 digs3 digs2 digs1 digs0 number of display digits (display mode 1) dspm05 = 0 0000 disabled display (static display) note 00012 00103 00114 01005 01016 01107 01118 10009 100110 101011 101112 110013 110114 111015 111116 number of display patterns (display mode 2) dspm05 = 1 disabled display (static display) note 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 note when display is disabled, a port output latch can be operated to enable static display. remark f x : oscillation frequency of the main system clock dspm05 : bit 5 of display mode register 0
46 78k/0 series application note 3.1 switching pcc after reset by issuing the reset signal, the slowest mode (processor clock control register(pcc) = 04h) of main system clock is selected for the cpu clock. as a result, when running at the maximum speed, pcc is rewritten and the cpu clock is set to the maximum speed (pcc = 00h). however, in order to operate at the maximum speed mode, the v dd pin voltage must be increased to the range where high-speed operation is possible and be stable. in this example, the time until the voltage increase is awaited by the watch timer (3.91-ms interval period selected). after the wait, the cpu clock switches to the maximum speed. figure 3-7. cpu clock switching after reset ( m PD78044F subseries) on off 4.5 v 2.7 v h l cpu clock wait time reset signal v dd pin voltage working power supply halt state 31.3 ms (2 17 /f x : 4.19-mhz operation) after the v dd pin voltage rises above 2.7 v, the reset signal is released 10 s later and cpu clock oscillation starts. before pcc switches, the v dd pin voltage increases above 4.5 v. 7.63 s 3.9 ms 0.48 s (1) spd chart set the watch timer to 3.91 ms. while : there is no interrupt request for the watch timer (! tmif3). clear tmif3 set pcc to the maximum-speed mode. (2) program listing ;****************************** ;* wait setting ;****************************** tcl2=#00010000b tmc2=#00110110b ; set the watch timer to 3.91 ms. while_bit(!tmif3) ; 3.91 ms? endw clr1 wtif pcc=#00000000b ; set the cpu clock to the maximum speed.
47 chapter 3 system clock switching application 3.2 switching during power on/off the 78k/0 series can select the subsystem clock based on the processor clock control register(pcc) setting and can operate with an ultralow power consumption. consequently, by adding a backup power, such as a nicd battery or super capacitor, to the system, operation can continue even when power fails. in this example, by detecting whether the power is on or off in intp1 (select detection edge by detecting both the rising and falling edges), the on or off decision is made based on this port level and pcc switches. figure 3-8 shows an example circuit. figure 3-9 shows the switching timing of the system clock. figure 3-8. example of the system clock switching circuit intp1/p01 v ss v dd PD78044F +5.6 v
48 78k/0 series application note figure 3-9. system clock switching during power on and off ( m PD78044F subseries) on off 6.0 (v) h l system clock p01/intp1 pin v dd pin voltage working power supply 4.5 (v) 2.7 (v) main system clock subsystem clock main system clock interrupt request generated wait until v dd rises above 4.5 v. interrupt request generated (1) spd chart if : power off (p01 = low level) intp1 then set the cpu clock to the low-speed mode. user processing else set the cpu clock to the high-speed mode. user processing
49 chapter 3 system clock switching application (2) program listing vep0 cseg at 08h dw intp1 ; intp1 vector address setting mov intm0,#00110000b ; both edge detection mode clr1 pmk1 ei ;**************************************** ;* low-speed/high-speed mode setting ;**************************************** intp1: if_bit(!p0.1) ; on-chip hardware setting (low speed) ; user processing pcc=#10010000b ; set to low-speed mode. else ; on-chip hardware setting (high speed) ; user processing pcc=#00000000b ; set to high-speed mode. endif reti
50 78k/0 series application note [memo]
51 chapter 4 watchdog timer application chapter 4 watchdog timer application the watchdog timer in the 78k/0 series has the two functions of a watchdog timer mode to detect runaway operation of the microcontroller and an interval timer mode. the watchdog timer is set by timer clock selection register 2 (tcl2), watchdog timer mode register (wdtm), and watchdog timer clock selection register (wdcs). cautions 1. wdcs is incorporated into the m pd780228 subseries only. 2. the format of the registers incorporated into the m pd780228 subseries differs from that of the registers incorporated into the m PD78044F, m pd78044h, and m pd780208 subseries. when using any of the sample programs described in this chapter with the m pd780228 subseries, replace the register settings with those for the m pd780228 subseries. * *
52 78k/0 series application note figure 4-1. format of timer clock selection register 2 ( m PD78044F, m pd78044h, and m pd780208 subseries) 7 tcl27 6 tcl26 5 tcl25 4 tcl24 3 0 2 tcl22 1 tcl21 0 tcl20 symbol tcl2 address ff42h at reset 00h r/w r/w tcl22 0 0 0 0 1 1 1 1 tcl21 0 0 1 1 0 0 1 1 tcl20 0 1 0 1 0 1 0 1 tcl24 0 1 count clock selection for the watch timer note f x /2 8 (19.5 khz) f xt (32.768 khz) tcl27 0 1 1 1 1 tcl26 x 0 0 1 1 tcl25 x 0 1 0 1 f x /2 10 (4.9 khz) f x /2 11 (2.4 khz) f x /2 12 (1.2 khz) setting prohibited selection of the buzzer output frequency buzzer output prohibited count clock selection f x /2 3 (625 khz) f x /2 4 (313 khz) f x /2 5 (156 khz) f x /2 6 (78.1 khz) f x /2 7 (39.1 khz) f x /2 8 (19.5 khz) f x /2 9 (9.8 khz) f x /2 11 (2.4 khz) watchdog timer mode f x /2 4 (313 khz) f x /2 5 (156 khz) f x /2 6 (78.1 khz) f x /2 7 (39.1 khz) f x /2 8 (19.5 khz) f x /2 9 (9.8 khz) f x /2 10 (4.9 khz) f x /2 12 (1.2 khz) interval timer mode note when a main system clock at 1.25 mhz or lower and an fip controller/driver are used simultaneously, select f x /2 8 as the count clock for the watch timer. caution when tcl2 will be rewritten with data other than identical data, rewrite after temporarily stopping timer operation. remarks 1. f x : main system clock oscillation frequency 2. f xt : subsystem clock oscillation frequency 3. x : dont care 4. the values in parentheses apply to operation with f x = 5.0 mhz or f xt = 32.768 khz.
53 chapter 4 watchdog timer application figure 4-2. format of the watchdog timer mode register ( m PD78044F, m pd78044h, and m pd780208 subseries) 7 run 6 0 5 0 4 wdtm4 3 wdtm3 2 0 1 0 0 0 symbol wdtm address fff9h at reset 00h r/w r/w wdtm4 0 1 1 wdtm3 x 0 1 run 0 1 operating mode selection for the watchdog timer note 1 interval timer mode note 2 (during overflow, a maskable interrupt request is issued.) watchdog timer mode 1 (during overflow, a non-maskable interrupt request is issued.) watchdog timer mode 2 (during overflow, reset operation starts.) selection of watchdog timer operation note 3 stop count after clearing the counter, start the count. notes 1. when wdtm3 and wdtm4 are set to 1 once, they cannot be cleared to 0 by software. 2. in this mode, the watchdog timer start operating as an interval timer immediately after run is set to 1. 3. when run is set once to 1, it cannot be cleared to 0 by software. as a result, when the count starts, stopping by means other than reset input is not possible. cautions 1. when run is set to 1 and the watchdog timer work was cleared, the period of an actual overflow becomes a maximum of 0.5% shorter than the time set in timer clock selection register 2. 2. when watchdog timer mode 1 or 2 is being used, check that the interrupt request flag (tmif4) is set to 0 and set wdtm4 to 1. if wdtm4 is set to 1 while tmif4 is set to 1, a non-maskable interrupt request occurs regardless of the contents of wdtm3. remark x: dont care *
54 78k/0 series application note figure 4-3. format of the watchdog timer mode register ( m pd780228 subseries) 7 run symbol wdtm address fff9h at reset 00h r/w r/w 6 0 5 0 wdtm4 wdtm3 operating mode selection for the watchdog timer note 1 0 x interval timer mode (during overflow, a maskable interrupt request is issued.) 1 0 watchdog timer mode 1 (during overflow, a non-maskable interrupt request is issued.) 1 1 watchdog timer mode 2 (during overflow, reset operation starts.) 4 wdtm4 3 wdtm3 2 0 1 0 0 0 run selection of watchdog timer operation note 2 0 stop count 1 after clearing the counter, start the count. notes 1. when wdtm3 and wdtm4 are set to 1 once, they cannot be cleared to 0 by software. 2. when run is set once to 1, it cannot be cleared to 0 by software. as a result, when the count starts, stopping by means other than reset input is not possible. caution when run is set to 1 and the watchdog timer work was cleared, the period of an actual overflow becomes a maximum of 0.5% shorter than the set time. remark x: dont care *
55 chapter 4 watchdog timer application figure 4-4. format of the watchdog timer clock selection register (only for the m pd780228 subseries) 7 0 symbol wdcs address ff42h at reset 00h r/w r/w 6 0 5 0 wdcs2 wdcs1 wdcs0 overflow time of the watchdog/interval timer 0002 12 /f x (819 s) 2 13 /f x (1.64 ms) 2 14 /f x (3.28 ms) 2 15 /f x (6.55 ms) 2 16 /f x (13.1 ms) 2 17 /f x (26.2 ms) 2 18 /f x (52.4 ms) 2 20 /f x (210 ms) 001 010 011 100 4 0 3 0 2 wdcs2 1 wdcs1 0 wdcs0 101 110 111 remarks 1. f x : oscillation frequency of the main system clock 2. the values in parentheses apply to operation with f x = 5.0 mhz. *
56 78k/0 series application note 4.1 setting the watchdog timer mode in processing operation of the watchdog timer after detecting the runaway, there is reset processing or non-maskable interrupt servicing. either one can be selected by the watchdog timer mode register (wdtm). when the watchdog timer mode is used, the timer must be cleared in a time interval shorter than the set runaway detection time. when the timer is not cleared, an overflow occurs and reset or interrupt servicing is executed. the runaway detection time for the watchdog timer is set in timer clock selection register 2(tcl2). in this example, 7.81 ms is selected in the runaway detection time and reset processing operation is selected when an overflow occurs. (1) spd chart set 7.81 ms in the runaway detection timer of the watchdog timer clear the watchdog timer. the reset starting mode is set in the watchdog timer. user processing 1 user processing 2 clear the watchdog timer. user processing 3 clear the watchdog timer.
57 chapter 4 watchdog timer application (2) program listing ;******************************** ;* watchdog timer setting ;******************************** tcl2=#00000100b ; set the watchdog timer to 7.81 ms. wdtm=#10011000b ; set the reset start mode. ; user processing 1 set1 run ; timer clear ; user processing 2 set1 run ; timer clear ; user processing 3 set1 run ; timer clear C C C C C C C C C C C C C C C C C C C C C
58 78k/0 series application note 4.2 interval timer mode setting when the interval timer mode is used, the interval time is set in timer clock selection register 2(tcl2) (interval time = 977 m s to 250 ms at f x = 4.19 mhz). this interval timer sets the interrupt request flag (tmif4) when the timer overflows. in this example, setting the three times of 977 m s, 7.82 ms, and 250 ms is illustrated. figure 4-5. count timing of the watchdog timer timer count intwdt fc fd fe ff 00 01 02 03 fd fe ff 00 (1) program listing <1> setting 977 m s tcl2 = #00000000b ; set to 977 m s. wdtm = #10001000b ; select the interval timer mode. <2> setting 7.82 ms tcl2 = #00000011b ; set to 7.82 ms. wdtm = #10001000b ; select the interval timer mode. <3> setting 250 ms tcl2 = #00000111b ; set to 250 ms. wdtm = #10001000b ; select the interval timer mode.
59 chapter 5 16-bit timer/event counter application chapter 5 16-bit timer/event counter application the 16-bit timer/event counter in the 78k/0 series supports the following functions: ? interval timer ? pwm output ? pulse width measurement ? external event counter ? square wave output the 16-bit timer/event counter requires the setting of the following six registers: ? timer clock selection register 0 (tcl0) ? 16-bit timer mode control register (tmc0) ? 16-bit timer output control register (toc0) ? port mode register 3 (pm3) ? external interrupt mode register (intm0) ? sampling clock selection register (scs)
60 78k/0 series application note figure 5-1. format of timer clock selection register 0 other than the above 7 cloe 6 tcl06 5 tcl05 4 tcl04 3 tcl03 2 tcl02 1 tcl01 0 tcl00 symbol tcl0 address ff40h at reset 00h r/w r/w tcl06 0 0 0 0 1 tcl05 0 0 1 1 0 tcl04 0 1 0 1 0 ti0 (valid edge settable) f x (5.0 mhz) f x /2 (2.5 mhz) f x /2 2 (1.25 mhz) f x /2 3 (625 khz) setting prohibited cloe 0 1 pcl output control output prohibited output enabled tcl03 0 0 1 1 1 1 1 tcl02 0 1 0 0 0 0 1 tcl01 0 1 0 0 1 1 0 f xt (32.768 khz) f x /2 3 (625 khz) f x /2 4 (313 khz) f x /2 5 (156 khz) f x /2 6 (78.1 khz) f x /2 7 (39.1 khz) f x /2 8 (19.5 khz) setting prohibited tcl00 0 1 0 1 0 1 0 other than the above pcl output clock selection selection of the count clock of the 16-bit timer register cautions 1. setting the valid edge for the ti0/intp0 pin is performed by the external interrupt mode register (intm0). in addition, selecting the frequency of the sampling clock is performed by the sampling clock selection register (scs). 2. after setting tcl00 to tcl03 when pcl output is enabled, set 1 in cloe by using a 1-bit memory manipulation instruction. 3. when the tm0 count clock is ti0 and the count value is read, read from tm0 and not from the capture register (cr01). 4. when data other than identical data will be rewritten in tcl0, rewrite after temporarily stopping timer operation. remarks 1. f x : main system clock oscillation frequency 2. f xt : subsystem clock oscillation frequency 3. ti0 : input pin of the 16-bit timer/event counter 4. tm0: 16-bit timer register 5. the values in parentheses apply to operation with f x = 5.0 mhz or f xt = 32.768 khz.
61 chapter 5 16-bit timer/event counter application figure 5-2. format of the 16-bit timer mode control register ovf0 overflow detection of the 16-bit timer register 0 no overflow 1 overflow tmc03 tmc02 tmc01 selection of operating selection of to0 output interrupt request generation mode and clear mode timing 0 0 0 stop operation no change not generated (clear tm0 to 0.) 0 0 1 pwm mode (free running) pwm pulse output generated when tm0 and cr00 match 0 1 0 free running mode tm0 and cr00 match. 0 1 1 tm0 and cr00 match or valid edge occurs at ti0. 1 0 0 when there is a valid edge tm0 and cr00 match. at ti0, clear and start. 1 0 1 tm0 and cr00 match or valid edge occurs at ti0. 1 1 0 when tm0 and cr00 tm0 and cr00 match. match, clear and start. 1 1 1 tm0 and cr00 match or valid edge occurs at ti0. cautions 1. perform switching of the clear mode and to0 output timing after timer operation is stopped (set 000 in tmc01-tmc03.) 2. setting the valid edge of the ti0/intp0 pin is performed by the external interrupt mode register (intm0). in addition, the sampling clock frequency is specified in the sampling clock selection register (scs). 3. when pwm mode is used, after setting the pwm mode, set the data in cr00. 4. when tm0 and cr00 matched and the mode to clear and start was selected, the cr00 setting is ffffh. when the value in tm0 changes from ffffh to 0000h, the ovf0 flag is set to 1. 5. the 16-bit timer register begins operating when a value other than 000 (operation stop mode) is set in tmc01-tmc03. to stop the operation, set 000 in tmc01-tmc03. 7 0 6 0 5 0 4 0 3 tmc03 2 tmc02 1 tmc01 0 ovf0 symbol tmc0 address ff48h at reset 00h r/w r/w
62 78k/0 series application note remarks 1. to0 : output pin of the 16-bit timer/event counter 2. ti0 : input pin of the 16-bit timer/event counter 3. tm0 : 16-bit timer register 4. cr00 : compare register 00 figure 5-3. format of the 16-bit timer output control register 7 0 6 0 5 0 4 0 3 lvs0 2 lvr0 1 toc01 0 toe0 symbol toc0 address ff4eh at reset 00h r/w r/w toe0 0 1 output control of the 16-bit timer/event counter lvs0 0 0 1 1 lvr0 0 1 0 1 setting the state of the timer output flip-flop of the 16-bit timer/event counter toc01 0 1 pwm mode selection of active level active high active low mode other than pwm mode output prohibited (port mode) output enabled control of timer output flip-flop inverse operation prohibited inverse operation enabled no change reset the timer output flip-flop (0) set the timer output flip-flop (1) setting prohibited cautions 1. always set toc0 after timer operation has stopped. 2. 0 is read from lvs0 and lvr0 when read after setting data.
63 chapter 5 16-bit timer/event counter application figure 5-4. format of the port mode register 3 7 pm37 6 pm36 5 pm35 4 pm34 3 pm33 2 pm32 1 pm31 0 pm30 symbol pm3 address ff23h at reset ffh r/w r/w pm3n 0 1 i/o mode selection of pin p3n (n = 0 to 7) output mode (output buffer on) input mode (output buffer off) caution when the p30/to0 pin is used for timer output, set 0 in the output latches of pm30 and p30. figure 5-5. format of the external interrupt mode register 7 es31 6 es30 5 es21 4 es20 3 es11 2 es10 1 0 0 0 symbol intm0 address ffech at reset 00h r/w r/w es11 0 0 1 1 es10 0 1 0 1 valid edge selection for intp0 falling edge rising edge setting prohibited both rising and falling edges es21 0 0 1 1 es20 0 1 0 1 valid edge selection for intp1 falling edge rising edge setting prohibited both rising and falling edges es31 0 0 1 1 es30 0 1 0 1 valid edge selection for intp2 falling edge rising edge setting prohibited both rising and falling edges caution set the valid edge of the intp0/ti0/p00 pin after timer operation is stopped by setting 0 in bits 1 to 3 (tmc01 to tmc03) of the 16-bit timer mode control register (tmc0). remarks 1. the intp0 pin also acts as the ti0/p00 pin. 2. the intp3 pin use the falling edge only. *
64 78k/0 series application note figure 5-6. format of the sampling clock selection register 7 0 6 0 5 0 4 0 3 0 2 0 1 scs1 0 scs0 symbol scs address ff47h at reset 00h r/w r/w scs1 0 0 1 1 scs0 0 1 0 1 selection of the intp0 sampling clock f x /2 n+1 setting prohibited f x /2 6 (78.1 khz) f x /2 7 (39.1 khz) caution f x /2 n+1 is the clock supplied to the cpu. f x /2 6 and f x /2 7 are the clocks supplied to peripheral hardware. f x /2 n+1 stops in the halt mode. remarks 1. n: value (n = 0 to 4) set in bits 0 to 2 (pcc0 to pcc2) in the processor clock control register (pcc) 2. f x : main system clock oscillation frequency 3. the values in parentheses apply to operation with f x = 5.0 mhz.
65 chapter 5 16-bit timer/event counter application 5.1 interval timer setting when the interval timer is used, first the timer clock selection register (tcl0) and 16-bit timer mode control register (tmc0) are set. the clear mode of the 16-bit timer is set in tmc0. the interval time is set in tcl0. then, the setting time and the compare register (cr00) from the count clock are set. the setting time is set by the following procedure. setting-time = (compare-register-value + 1) x count-clock-period this example illustrates how to set the setting time of interval timer to 10 ms and 50 ms. (a) for a 10 ms interval <1> tmc0 setting select clear and start when tm0 and cr00 match. <2> tcl0 setting a setting greater than 10 ms is possible and the f x mode with the highest resolution is selected. <3> cr00 setting 10 ms = (n + 1) x 1 4.19 mhz n = 10 ms x 4.19 mhz C 1 = 41899 (1) program listing cr00=#41899 tcl0=#00010000b ; select the count clock f x . tmc0=#00001100b ; the 16-bit timer/event counter is set to clear and start when tm0 and cr00 match. . .
66 78k/0 series application note (b) for a 50-ms interval <1> tmc0 setting select clear and start when tm0 and cr00 match. <2> tcl0 setting a setting greater than 50 ms is possible and the f x /2 2 mode with the highest resolution is selected. <3> cr00 setting 50 ms = (n + 1) x 1 4.19 mhz/2 2 n = 50 ms x 4.19 mhz/2 2 C 1 = 52374 (1) program listing cr00=#52374 tcl0=#00110000b ; select the count clock f x /2 2 . tmc0=#00001100b ; the 16-bit timer/event counter is set to clear and start when tm0 and cr00 match. . .
67 chapter 5 16-bit timer/event counter application 5.2 pwm output when the pwm output is used, set the pwm mode in the 16-bit timer mode control register (tmc0) and the 16-bit timer/event counter in the output enabled state in the 16-bit timer output control register (toc0). the pwm pulse width (active level) is determined by the value set in cr00. however, because pwm in the 78k/0 series has 14-bit resolution, bits 2 to 15 become valid in the compare register (cr00). (set bits 0 and 1 in cr00 to 0.) in this example, the basic period of the pwm mode is set to 61.0 m s (2 8 /f x ) and the active level is set to active-low. also, the pulse width setting program rewrites the high-order 4 bits based on a parameter (00h to 0fh). consequently, this application example can have a pwm output in 16 steps (cr00 = 0ffch to fffch). (1) package description pwm : pwm output subroutine name pwmout : input parameter of pwm active level ax name use attribute byte pwmout pwm active-level setting saddr 1 1 level, 2 bytes ? 16-bit timer/event counter ? p30/to0 ? 16-bit timer/event counter setting pwm output mode tmc0=#00000010b basic pwm period of 61.0 m s tcl0=#00010000b active-low output toc0=#00000011b ? p30 output mode pm30=0 ? p30 output latch p30=0 after setting data in pwmout of the ram, call the subroutine pwm.
68 78k/0 series application note (2) use example extrn pwm,pwmout toc0=#00000011b ; setting pwm output and active-low tcl0=#00010000b ; select the count clock f x . tmc0=#00000010b ; pwm mode setting pwmout=a ; input parameter setting of active level call !pwm (3) spd chart data read of pwmout decode in the high-order 4-bit data of cr00 set xffch in cr00 (x : 0 to fh). pwm (4) program listing public pwm,pwmout pwm_dat dseg saddr pwmout: ds 1 ; pwm output data area (0 to 15) ;************************************ ;* pwm output (16 levels) ;************************************ po_seg cseg pwm: a=pwmout ; read high-order data of pwmout a<<=1 a<<=1 a<<=1 a<<=1 a!=#0fh ; set low-order 12 bits in 0ffch. x=#0fch cr00=ax ret . . . . . .
69 chapter 5 16-bit timer/event counter application 5.3 remote control reception two examples of programs are introduced for remote control reception using the 16-bit timer/event counter. ? the counter is cleared when a valid edge is detected by the remote control. the pulse width from the timer count value (capture register cr01) is measured until the next valid edge is detected. ? the timer is allowed to run freely and the pulse width is measured from the difference in the counter between valid edges. in addition, this is synchronized to the pwm output. the remote control signal is received by a pin light receiving diode, introduced to the m pc1490 receiving preamplifier for remote control and input at pin p00/intp0. an example remote control circuit is shown in figure 5-7. the format of the remote control signal is shown in figure 5-8. figure 5-7. example of the remote control receiving circuit ph310 160 k w 100 f pc1490 in c d in + gnd c 1 f 0 v cc out 4.7 w 10 f 1000 pf 1 f shielded case 100 k w v dd gnd intp0/p00 PD78044F +5 v
70 78k/0 series application note figure 5-8. ic output signal for remote control transmission time during 455-khz oscillation 108 ms 108 ms 67.5 ms 9 ms 13.5 ms leader code custom code 8 bits custom code 8 bits 27 ms 67.5 ms data code 8 bits data code 8 bits 27 ms first time second and later times (transmission only when continuing to push the key) 9 ms 4.5 ms 13.5 ms 2.25 ms 1.125 ms 0.56 ms 01 100 1 9 ms 2.25 ms 11.25 ms 0.56 ms 4.5 ms
71 chapter 5 16-bit timer/event counter application because the m pc1490 preamplifier for remote control reception used in this circuit example is active- low, the level inputs to the m PD78044F subseries become inverted data of the data transmitted by the remote control. figure 5-9. output signal of the receiving preamplifier h l pc1490 output 9 ms 4.5 ms leader code
72 78k/0 series application note 5.3.1 remote control reception by a counter clear in this program, the valid pulse width when receiving a remote control signal is shown in table 5-1 and the processing for each signal is described in <1> to <6> . the repeat signal of the remote control signal is valid for only the 250 ms following a valid input. also, when a signal is input within 3 ms after a normal read, data is also invalid. table 5-1. valid time for input signal signal name output time valid time leader code (low) 9 ms 6.8 ms-11.8 ms leader code (high) normal 4.5 ms 3 ms-5 ms repeat 2.25 ms 1.8 ms-3 ms custom code/data code 0 1.125 ms 0.5 ms-1.8 ms 1 2.25 ms 1.8 ms-2.5 ms <1> leader code (low) the interval of the 16-bit timer/event counter is set to 1.5 ms and port level sampling is performed by interrupt servicing. when the low-level input is detected five consecutive times, a leader code is judged to be present and the interval changes to 7.81 ms. then, by having an interrupt request at the rising edge of intp0, the low-level pulse width of the leader code is measured. figure 5-10. sampling the remote control signal interval time 1.5 ms 7.81 ms noise noise valid when there are 5 consecutive lows
73 chapter 5 16-bit timer/event counter application <2> leader code (high) based on an interrupt request at the falling edge at intp0, the high-level pulse width of the leader code is measured by the timer counter. <3> custom/data code based on an interrupt request at the falling edge at intp0, the pulse width is measured at every bit (1 period). after the 32nd bit of data is read in, a match of the inverted data and custom code is tested. furthermore, the absence of data at the 33rd bit is verified. <4> repeat code detection when the high level of the leader code is less than 3 ms, the pulse width is measured until a rising edge occurs at intp0 after the leader code is output. <5> valid period of the repeat code after valid data is input, there is sampling by interrupt servicing of the 16-bit timer/event counter (1.5 ms interval) and the valid period of 250 ms for the repeat code is measured. <6> time out during pulse width measurement when an interrupt request (7.81 ms) of the 16-bit timer/event counter occurred during pulse width measurement, a time out occurs and the data become invalid. (1) package description rmdata : saves remote control reception data rpt : decision flag for the repeat valid interval ipdtfg : decision flag indicating the presence of valid data rmdtok : decision flag indicating the presence of a valid input signal rmdtset : decision flag indicating the presence of an input signal bank 0: ax, bc, hl
74 78k/0 series application note name use attribute byte rptct repeat code valid time counter saddr 1 rmendct no input time counter after data input selmod mode selection ld_ct leader signal detection counter rmdata valid data storage area workp input signal storage area saddrp 4 name use ipdtfg presence of valid data rmdtok presence of a valid input signal rmdtset presence of an input signal rpt decision on whether the repeat valid interval has elapsed 5 levels, 12 bytes ? 16-bit timer/event counter ? p00/intp0 ? 16-bit timer/event counter setting time clear mode when tm0 and cr00 match tmc0 = #00001100b count/clock f x tcl0 = #00010000b compare register 00 cr00 = #6290 ? intp0 sampling clock f x /2 7 scs = #00000011b ? intp0 high-priority interrupt request ppr0 = 0 ? 16-bit timer/event counter interrupt enabled tmmk0 = 0 ? define custom code in cstm. this is a public declaration. ? ram clear start using the intp0 and inttm0 interrupt requests.
75 chapter 5 16-bit timer/event counter application (2) example use public cstm extrn rmdata,rptct extbit rpt,rmdtset,ipdtfg cstm equ 9dh ; remote control custom code cr00=#6290 tcl0=#00010000b ; set to 1.5 ms. tmc0=#00001100b scs=#00000011b ; intp0 sampling clock is f x /128. clr1 ppr0 ; high priority intp0 clr1 rpt ; clear flag clr1 ipdtfg clr1 rmdtset clr1 tmmk0 ; enable timer interrupt ei dt_test: if_bit(rmdtset) clr1 rmdtset if_bit(rpt) ; ; repeat processing ; else ; ; input present processing ; endif else if_bit(!rpt) ; ; no input present processing ; endif endif
76 78k/0 series application note (3) spd chart select register bank 1. enable mask interrupt if : an input signal is present (ipdtfg) inttm0 then if : valid data is present (rmdtok) then if : there is no input within the repeat valid time (250 ms). then set in the repeat code invalid state. clear rpt, ipdtfg, and rmdtok. else leader low time count s_lowct else if : there is no input after data input (within 4.5 ms) then initialize leader low detection counter. else leader low time count s_lowct if : leader low detection mode s_lowct then if : p00 = low then if : p00 = low five consecutive times then select leader low measurement mode. set the 16-bit timer to 7.81 ms. set to intp0 rising edge detection mode. intp0 interrupt enabled. initialize leader low detection counter. else initialize leader detection counter. else set to leader low detection mode. s_m0set initialize leader detection counter. count the repeat valid time. set that valid data is present. set rmdtok and rmdtset. set to leader low detection mode s_m0set
77 chapter 5 16-bit timer/event counter application select register bank 0. 100-? wait wait case : selmod intp0 of : 1 if : p00 = high lead_l then 100-? wait wait if : p00 = high leader low measurement mode lead_l leader high measurement mode lead_h custom code/data read mode cdcode repeat code detection mode repcd error data detection mode endchk of : 2 of : 3 of : 4 of : 5 then timer read cr_read if : 6.8 ms leader low 11.8 ms then select leader high detection mode. set to intp0 falling edge detection mode. else set to leader low detection mode. s_m0set if : p00 = low lead_h then 100-? wait wait if : p00 = low then timer read cr_read if : 2 ms leader high 5 ms then if : leader high 3 3 ms else then select the custom code/data read mode. initialize the data storage area. else select the repeat detection mode. set the intp0 rising edge detection mode. set to leader low detection mode. s_m0set
78 78k/0 series application note if : p00 = low cdcode then 100-? wait wait if : p00 = low then timer read cr_read if : 0.5 ms < input data 2.5 ms then if : input data 3 1.8 ms then set cy. else clear cy. save cy in the data storage area. if : end of 32-bit data input then if : custom code match then if : match of inversed data of custom/data code then save data code. set in the input data present state. set ipdtfg and clear rmdtset, rpt, and rmdtok. set to error data detection mode. s_m5set else set to leader low detection mode. s_m0set else set to leader low detection mode. s_m0set else set to leader low detection mode. s_m0set if : p00 = high repcd then then if : valid data is present. then timer read cr_read if : repeat code 1 ms then set in the repeat code valid state. set rpt. else set to leader low detection mode. s_m0set else set to error data detection mode. s_m5set 100-? wait wait if : p00 = high set to error data detection mode. s_m5set set in the end of data input state.
79 chapter 5 16-bit timer/event counter application if : p00 = low endchk then then set in the invalid input signal state. clear ipdtfg and rpt. set to leader low detection mode. s_m0set read capture register. stop operation of 16-bit timer. start timer. cr_read select the leader low detection mode. intp0 interrupt prohibited set the 16-bit timer to 1.5 ms s_m0set select the error data detection mode. set the counter for the repeat valid time. set the 16-bit timer to 1.5 ms. s_m5set 100-? wait wait if : p00 = low
80 78k/0 series application note (4) program listing public rpt,ipdtfg,rmdtok,rmdtset public rmendct,rptct,selmod,ld_ct,rmdata extrn cstm rm_dat dseg saddr rptct: ds 1 ; repeat code valid time counter rmendct: ds 1 ; no input time counter after data input selmod: ds 1 ; mode selection ld_ct: ds 1 ; leader signal detection counter rmdata: ds 1 ; valid data storage area rm_datp dseg saddrp workp: ds 4 ; input signal storage area bseg ipdtfg dbit ; valid data is present. rmdtok dbit ; input signal is valid. rmdtset dbit ; input signal is present. rpt dbit ; repeat code valid period vep0 cseg at 06h dw intp0 ; intp0 vector address setting vetm0 cseg at 14h dw inttm0 ; 16-bit timer vector address setting ;********************************************* ; remote control signal timer processing ;********************************************* tm0_seg cseg inttm0: sel rb1 ei ; interrupt enabled (intp0) if_bit(ipdtfg) ; is the input signal present? if_bit(rmdtok) ; is the data valid? rptct-- if(rptct==#0) ; repeat invalid time clr1 rpt ; repeat code invalid state clr1 ipdtfg clr1 rmdtok endif call !s_lowct else rmendct-- if(rmendct==#0) set1 rmdtok ; set to valid data is present. set1 rmdtset call !s_m0set ; set to leader (low) detection mode. endif ld_ct=#5 endif else call !s_lowct endif ret1
81 chapter 5 16-bit timer/event counter application s_lowct: if(selmod==#0) ; leader (low) detection mode? if_bit(!p0.0) ld_ct-- if(ld_ct==#0) selmod=#1 ; leader (low) measurement mode tmc0=#00000000b cr00=#32767 ; 7.81-ms timer tmc0=#00001100b intm0=#00000100b clr1 pif0 clr1 pmk0 ; intp0 interrupt enabled ld_ct=#5 endif else ld_ct=#5 endif else call !s_m0set ; set to leader (low) detection mode. ld_ct=#5 endif ret $eject ;********************************************************* ;* remote control signal edge detection processing ;********************************************************* p0_seg cseg intp0; sel rb0 call !wait ; 100- m s wait switch(selmod) case 1: call !lead_l ; leader low detection processing break case 2: call !lead_h ; leader high detection processing break case 3: call !cdcode ; custom/data code read processing break case 4: call !repcd ; repeat code detection processing break case 5: call !endchk ; error data detection processing ends reti
82 78k/0 series application note ;****************************** ;* leader low detection ;****************************** lead_l: if_bit(p0.0) ; level check p0.0 = 0:noise call !wait ; 100- m s wait if_bit(p0.0) call !cr_read ; timer value read if(ax>=#3354) ; 6.8 ms C (1.5 ms x 4) if(ax<#18035) ; 11.8 ms C (1.5 ms x 5) selmod=#2 ; leader high detection mode intm0=#00000000b ; intp0 falling edge else call !s_m0set ; set to leader (low) detection mode. endif else call !s_m0set ; set to leader (low) detection mode. endif endif endif ret $eject ;***************************** ;* leader high detection ;***************************** lead_h: if_bit(!p0.0) ; level check p0.0 = 1:noise call !wait ; 100- m s wait if_bit(!p0.0) call !cr_read ; timer value read if(ax>=#5710-160/2) ; 1.8 ms C 100 m s x 2 C 160 clocks (edge detection -> timer start) if(ax<#20132-160/2) ; 5 ms C 100 m s x 2 C 160 clocks (edge detection -> timer start) if(ax>#11743-160/2) ; custom/data code (3 ms C 100 m s x 2)? selmod=#3 ; data read mode workp=#0000h ; initialize work area. (workp)+2=#8000h ; set most significant bit to 1 (for verifying the end of data). else selmod=#4 ; repeat detection mode intm0=#00000100b ; intp0 rising endif else call !s_m0set ; set to leader (low) detection mode. endif else call !s_m0set ; set to leader (low) detection mode. endif endif endif ret $eject
83 chapter 5 16-bit timer/event counter application ;******************************* ;* custom/data code read ;******************************* cdcode: if_bit(!p0.0) ; level check p0.0 = 1:noise call !wait ; 100- m s wait if_bit(!p0.0) call !cr_read ; timer value read if(ax>=#1257-190/2) ; 0.5 ms - 100 m s x 2 C 190 clocks (edge detection -> timer start) if(ax<#9646-190/2) ; 2.5 ms - 100 m s x 2 C 190 clocks (edge detection -> timer start) if(ax>=#6710-190/2) ; 1.8 ms - 100 m s x 2 C 190 clocks (edge detection -> timer start) set1 cy else clr1 cy endif hl=#workp+3 ; set work area address. c=#4 ; set number of digits in work area. wkshft: a=[hl] ; 1-bit data save rorc a,1 ; 1-bit shift [hl]=a hl-- dbnz c,$wkshft ; completed the shift of all digits. if_bit(cy) ; is 32-bit input finished? if(workp+0==#cstm) (a) ; custom code check a^=workp+1 if(a==#0ffh) ; custom code inverted data check a=workp+2 a^=workp+3 ; data code inverted data check if(a==#0ffh) ; save input data. rmdata=workp+2 (a) ; set in the input data present state. set1 ipdtfg clr1 rmdtset clr1 rpt clr1 rmdtok call !s_m5set else ; set to leader (low) detection mode. call !s_m0set endif else ; set to leader (low) detection mode. call !s_m0set endif else call !s_m0set
84 78k/0 series application note endif endif else call !s_m0set ; set to leader (low) detection mode. endif else call !s_m0set ; set to leader (low) detection mode. endif endif endif ret $eject ;******************************* ;* repeat code detection ;******************************* repcd: if_bit(p0.0) ; level check p0.0 = 0:noise call !wait ; 100- m s wait if_bit(p0.0) if_bit(rmdtok) ; is valid data present? call !cr_read ; timer value read if(ax<=#3354-190/2) ; 1 ms C 100 m s x 2 C 190 clocks (edge detection -> timer start) set1 rpt clr1 rmdtok ; input signal check after the end of data clr1 rmdtset call !s_m5set else call !s_m0set ; set to leader (low) detection mode. endif else call !s_m0set ; set to leader (low) detection mode. endif endif endif ret $eject
85 chapter 5 16-bit timer/event counter application ;****************************************** ;* error data detection ;****************************************** endchk: if_bit(!p0.0) ; level check p0.0 = 1:noise call !wait ; 100- m s wait if_bit(!p0.0) clr1 !pdtfg ; error data input clr1 rpt ; input signal invalid call !s_m0set ; set to leader (low) detection mode. endif endif ret ;****************************************** ;* 100- m s wait ;****************************************** wait: b=#(838-14-12-8)/12 ; call(14), ret(12), mov(8) waitct: ; 100- m s setting dbnz b,$waitct ; 1 instruction, 12 clocks ret ;****************************************** ;* leader (low) detection mode setting ;****************************************** s_m0set: tmc0=#00000000b cr00=#6290 tcl0=#00010000b ; set timer to 1.5 ms. tmc0=#00001100b selmod=#0 ; leader (low) detection mode set1 pmk0 ret ;****************************************** ;* error data detection mode setting ;****************************************** s_m5set: rptct=#173 ; counter for 250-ms measurement selmod=#5 ; end of data input mode rmendct=#3 ; counter for no input verification tmc0=#00000000b ; operation stopped cr00=#6290 ; set to 1.5 ms. tmc0=#00001100b ret ;****************************************** ;* read timer count value ;****************************************** cr_read: ax=cr01 tmc0=#00000000b ; stop operation tmc0=#00001100b ; timer start ret
86 78k/0 series application note 5.3.2 remote control reception by pwm output and free running in this program, the valid pulse widths when the remote control signal is the received signal are shown in table 5-2. the processing methods for each signal are explained in <1> to <6> . table 5-2. valid time of the input signal signal name output time valid time leader code (low) 9 ms 3 ms-10 ms leader code (high) normal 4.5 ms 3 ms-5 ms repeat 2.25 ms 1.8 ms-3 ms custom code/data code 0 1.125 ms 0.5 ms-1.8 ms 1 2.25 ms 1.8 ms-2.5 ms <1> leader code (low) an interrupt request during the detection of the falling edge of intp0 causes the 16-bit capture register (cr01) value to be saved in memory. when the rising edge occurs, the pulse width is measured from the difference with the 16-bit compare register (cr00). <2> leader code (high) based on an interrupt request due to the falling edge of intp0, the pulse width during the high level of the leader code is measured by the timer count. <3> custom/data code based on an interrupt request due to the falling edge of intp0, the pulse width is measured for each bit (1 period). after the 32nd bit of data is read in, test for a match of the inverse data and custom code. furthermore, the absence of a 33rd bit of data is verified. <4> repeat code detection when the high level of the leader code is less than 3 ms, the pulse width is measured until the rising edge of intp0 after the leader code output. <5> valid time for repeat code after valid data input, the overflow flag (ovf0) of the 16-bit timer/event counter is tested in the main program. a valid time of 250 ms for the repeat code is measured. <6> time out during pulse width measurement the ovf0 of the 16-bit timer/event counter during pulse width measurement is tested in the main program. when detected twice, a time out occurs and data becomes invalid. because the 16-bit timer/event counter in this example is operated in the pwm output mode, by linking the program shown in section 5.2 , remote control reception and pwm output can be simultaneously executed.
87 chapter 5 16-bit timer/event counter application (1) package description tim_pro : name of subroutine for timer overflow processing rmdata : saves remote control reception data. rpt : decision flag for the repeat valid interval ipdtfg : decision flag indicating the presence of valid data rmdtok : decision flag indicating the presence of a valid input signal rmdtset : decision flag indicating the presence of an input signal ovsens : timer overflow detection flag in intp0 processing bank 0: ax, bc, hl name use attribute byte rptct time counter for valid repeat code saddr 1 rmendct no input time counter after data input selmod mode selection ld_ct leader signal detection counter rmdata valid data storage area to_cnt timer overflow detection counter cr01_np newest timer counter value storage area saddrp 2 cr01_op previous timer counter value storage area workp input signal storage area 4 name use ipdtfg presence of valid data rmdtok presence of valid input signal rmdtset presence of input signal rpt decision on whether the repeat valid interval has elapsed to_flg timer overflow present ovsens timer overflow detection in intp0 processing 5 levels, 11 bytes ? 16-bit timer/event counter ? p00/intp0 ? p30/to0
88 78k/0 series application note ? 16-bit timer/event counter setting pwm output mode tmc0 = #00000010b basic pwm period of 61.0 m s tcl0 = #00010000b active-low output toc0 = #00000011b ? p30 output mode pm30 = 0 ? intp0 sampling clock f x /2 7 scs = #00000011b ? intp0 high-priority interrupt request ppr0 = 0 ? intp0 interrupt enabled pmk0 = 0 ? define custom code in cstm. this is a public declaration. ? clear ram ? test ovf0 of the 16-bit timer/event counter. when ovf0 is set, call the tim_pro subroutine. ? start using an interrupt request based on the edge detection of the remote control signal.
89 chapter 5 16-bit timer/event counter application (2) example use public cstm extrn rmdata,rptct,pwm,pwmout,tim_pr0 extbit rpt,rmdtset,ipdtfg,to_flg,ovsens cstm equ 9dh ; custom code toc0=#00000011b ; setting of pwm output and active low tcl0=#00010000b ; select f x count clock. tmc0=#00000010b ; overflow present in pwm mode. intm0=#00000000b ; intp0 falling edge scs=#00000011b ; intp0 sampling clock of f x /128 clr1 ppr0 ; intp0 high priority clr1 rpt ; clear flag clr1 ipdtfg clr1 rmdtset clr1 pmk0 ; intp0 interrupt enabled ei dt_test: if_bit(ovsens) ; timer overflow detection in intp0 processing clr1 ovsens call !tim_pr0 elseif_bit(ovf0) ; timer overflow is present. clr1 ovf0 set1 to_flg call !tim_pr0 endif if_bit(rmdtset) clr1 rmdtset if_bit(rpt) ; ; repeat processing ; else ; ; input present processing ; endif else if_bit(!rpt) ; ; no input present processing ; endif endif mov pwmout.a call !pwm
90 78k/0 series application note (3) spd chart if : an input signal is present. tim_pro then if : there is valid data. then if : repeat code invalid period. then set in the repeat code invalid state. clear rpt, ipdtfg, and rmdtok. else if : there is no input after the end of data input (within 61.0 ? x 2) then set to valid data is present. set rmdtok and rmdtset. set to leader low detection mode. s_m0set else timer overflow check to_chk if : leader low detection mode. to_chk then set to no timer overflow else timer overflow count if : timer overflows twice then set to leader low detection mode. s_m0set select register bank 0. 100-? wait wait case : selmod intp0 of : 0 of : 1 of : 2 of : 3 of : 4 of : 5 timer overflow check to_chk error data detection mode endchk repeat code detection mode repcd custom code/data read mode cdcode leader high measurement mode lead_h leader low measurement mode lead_l leader low detection mode rm_sta
91 chapter 5 16-bit timer/event counter application if : p00 = low rm_sta then 100-? wait wait if : p00 = low then save data in capture register into memory. select leader low measurement mode 1. set to the intp0 rising edge detection mode. if : p00 = high lead_l then then timer read pw_ct if : 3 ms leader low 10ms then select the leader high detection mode. set to intp0 falling edge detection mode. set to leader low detection mode. s_m0set else if : p00 = low lead_h then then timer read pw_ct if : 2 ms leader high 5 ms then select custom code/data read mode. initialize the data storage area. select the repeat detection mode. set to intp0 rising edge detection mode. else then if : leader high 3 3 ms else set to leader low detection mode. s_m0set 100-? wait wait if : p00 = low 100-? wait wait if : p00 = low
92 78k/0 series application note if : p00 = low cdcode then then if : 0.5 ms < input data 2.5 ms then if : input data 3 1.8 ms then set cy. else clear cy. save cy in data storage area. if : end of 32-bit data input. then if : custom code match then if : inverse data of custom/data code match then save data code. set in the input data present state. set ipdtfg and clear rmdtset, rpt, and rmdtok. set to error data detection mode. s_m5set else set to leader low detection mode s_m0set else set to leader low detection mode s_m0set else set to leader low detection mode s_m0set if : p00 = high repcd then then if : valid data is present. then timer read pw_ct if : repeat code 1 ms then set in the repeat code valid state. set rpt. set in the end of data input state. set to error data detection mode. s_m5set else set to leader low detection mode. s_m0set else set to error data detection mode. s_m5set timer read cr_read 100- s wait wait if : p00 = high 100- s wait wait if : p00 = low
93 chapter 5 16-bit timer/event counter application if : p00 = low endchk then then set the input signal in the invalid state. clear ipdtfg and rpt. set to leader low detection mode. s_m0set select the leader low detection mode. clear to_flg. set to intp0 falling edge detection mode. s_m0set select the error data detection mode. set the counter for repeat valid time. s_m5set if : ovf occurs after edge detection. pw_ct then if : ovf generated < interrupt reception processing time or more (65 clocks) then set to timer overflow present. read capture register. subtract the capture register value from the previous value. if : borrow generated in the subtraction result (cy= 1) then if : there is timer overflow (to_flg = 1) then else if : there is timer overflow (to_flg = 1) then clear cy flag. set cy flag. save the value in the capture register into memory. 100-? wait wait if : p00 = low
94 78k/0 series application note (4) program listing public tim_pro,rpt,ipdtfg,rmdtok,rmdtset public rmendct,rptct,selmod,ld_ct,rmdata public to_flg,ovsens extrn cstm rm_dat dseg saddr rptct: ds 1 ; counter for repeat code valid time rmendct:ds 1 ; counter for no input time after data input selmod: ds 1 ; mode selection ld_ct ds 1 ; leader signal detection counter rmdata: ds 1 ; valid data storage area to_cnt: ds 1 ; timer overflow counter rm_datp dseg saddrp cr01_np:ds 2 ; newest timer counter value storage area cr01_op:ds 2 ; previous timer counter value storage area workp: ds 4 ; input signal storage area bseg !pdtfg dbit ; valid data is present. rmdtok dbit ; input signal is valid. rmdtset dbit ; input signal is present. rpt dbit ; repeat code valid period to_flg dbit ; timer overflow is present. ovsens dbit ; timer overflow detection in intp0 processing vep0 cseg at 06h dw intp0 ; setting of the intp0 vector address $eject ;*********************************************** ;* remote control signal timer processing ;*********************************************** tm0_seg cseg tim_pro: if_bit(ipdtfg) ; is an input signal present? if_bit(rmdtok) ; is the data valid? rptct-- if(rptct==#0) ; repeat invalid time clr1 rpt ; repeat code invalid state clr1 !pdtfg clr1 rmdtok endif else rmendct-- if(rmendct==#0) set1 rmdtok ; set to valid data is present. set1 rmdtset call !s_m0set ; set to leader (low) detection mode. endif endif else call !to_chk ; timer overflow check endif ret
95 chapter 5 16-bit timer/event counter application to_chk: if(selmod==#0) clr1 to_flg else to_cnt++ if(to_cnt==#2) call !s_m0set ; set to starting edge detection mode. endif endif ret $eject ;********************************************** ;* remote control signal edge detection ;********************************************** p0_seg cseg intp0: sel rb0 call !wait ; 100- m s wait switch(selmod) case 0: call !rm_sta ; starting edge detection break case 1: call !lead_l ; leader low detection break case 2: call !lead_h ; leader high detection break case 3: call !cdcode ; custom/data code read break case 4: call !repcd ; repeat code detection break case 5: call !endchk ; error data detection ends reti ;********************************************** ;* starting edge detection ;********************************************** rm_sta: clr1 to_flg ; timer counter starts if_bit(!p0.0) ; level check p0.0 = 1:noise call !wait ; 100- m s wait if_bit(!p0.0) cr01_op=cr01 (ax) ; save capture register. selmod=#1 ; leader low detection mode intm0=#00000100b ; intp0 rising edge to_cnt=#0 endif endif ret
96 78k/0 series application note ;****************************** ;* leader low detection ;****************************** lead_l: if_bit(p0.0) ; level check p0.0 = 1:noise call !wait ; 100- m s wait if_bit(p0.0) call !pw_ct ; timer value read if_bit(!cy) to_cnt=#0 if(ax>=#12582) ; 3 ms if(ax<#41942) ; 10 ms selmod=#2 ; leader high detection mode intm0=#00000000b ; intp0 falling edge else call !s_m0set ; set to starting edge detection mode. endif else call !s_m0set ; set to starting edge detection mode. endif else call !s_m0set ; set to starting edge detection mode. endif endif endif ret $eject ;****************************** ;* leader high detection ;****************************** lead_h: if_bit(!p0.0) ; level check p0.0 = 0:noise call !wait ; 100- m s wait if_bit(!p0.0) call !pw_ct ; timer value read if_bit(!cy) to_cnt=#0 if(ax>=#7549) ; 1.8 ms if(ax<#20971) ; 5 ms if(ax>#12582) ; custom/data code (3 ms)? selmod=#3 ; data read mode workp=#0000h ; initialize work area. (workp)+2=#8000h ; set the most significant bit to 1 (to verify the end of data). else selmod=#4 ; repeat detection mode intm0=#00000100b ; intp0 rising endif else call !s_m0set ; set to starting edge detection mode. endif else call !s_m0set ; set to starting edge detection mode. endif else call !s_m0set ; set to starting edge detection mode. endif endif endif ret $eject
97 chapter 5 16-bit timer/event counter application ;******************************* ;* custom/data code read ;******************************* cdcode: if_bit(!p0.0) ; level check p0.0 = 1: noise call !wait ; 100- m s wait if_bit(!p0.0) call !pw_ct ; timer value read if_bit(!cy) to_cnt=#0 if(ax>=#2096) ; 0.5 ms if(ax<#10485) ; 2.5 ms if(ax>=#7549) ; 1.8 ms set1 cy else clr1 cy endif hl=#workp+3 ; set work area address. c=#4 ; set the number of digits in the work area. wkshft: a=[hl] ; 1-bit data save rorc a,1 ; 1-bit shift [hl]=a hl-- dbnz c,$wkshft ; end of shifting all digits if_bit(cy) ; end of 32-bit input? ; custom code check if(workp+0==#cstm) (a) a^=workp+1 if(a==#0ffh) ; custom code inverse data check a=workp+2 ; data code inverse data check a^=workp+3 if(a==#0ffh) ; save input data. rmdata=workp+2 (a) ; set in the input data present state. set1 ipdtfg clr1 rmdtset clr1 rpt clr1 rmdtok call !s_m5set else ; set to starting edge detection mode. call !s_m0set endif else ; set to starting edge detection mode. call !s_m0set endif else call !s_m0set endif endif else call !s_m0set ; set to starting edge detection mode. endif else
98 78k/0 series application note call !s_m0set ; set to starting edge detection mode. endif else call !s_m0set ; set to starting edge detection mode. endif endif endif ret $eject ;****************************** ;* repeat code detection ;****************************** repcd: if_bit(p0.0) ; level check p0.0 = 1: noise call !wait ; 100- m s wait if_bit(p0.0) if_bit(rmdtok) ; is the data valid? call !pw_ct ; timer value read if_bit(!cy) to_cnt=#0 if(ax<=#4193) ; 1 ms set1 rpt clr1 rmdtok ; input signal check at the end of data clr1 rmdtset call !s_m5set else call !s_m0set ; set to starting edge detection mode. endif else call !s_m0set ; set to starting edge detection mode. endif else call !s_m0set ; set to starting edge detection mode. endif endif endif ret $eject
99 chapter 5 16-bit timer/event counter application ;********************************************* ;* error data detection ;********************************************* endchk: if_bit(!p0.0) ; level check p0.0 = 1:noise call !wait ; 100- m s wait if_bit(!p0.0) clr1 ipdtfg ; error data input clr1 rpt ; input signal invalid call !s_m0set ; set to starting edge detection mode. endif endif ret ;********************************************* ;* calculation of capture register value ;********************************************* pw_ct: if_bit(ovf0) ; ovf0 after edge detection? if(cr01<#10000-33) (ax) ; interrupt reception processing time = 65 clocks (max) clr1 ovf0 set1 ovsens set1 to_flg endif endif cr01_np=cr01 (ax) ; capture register value read a=cr01_np+0 ; ax=cr01_np-cr01_op a-=cr01_op x=a a=cr01_np+1 subc a,cr01_op+1 bc=ax ; calculation result save if_bit(cy) ; cr01_np>cr01_op if_bit(to_flg) ; timer overflow present (flag test). clr1 cy ; normal data endif else if_bit(to_flg) ; timer overflow set1 cy ; error occurred. endif endif cr01_op=cr01_np (ax) ax=bc ; calculation result restored. clr1 to_flg ret
100 78k/0 series application note ;******************************************** ;* 100- m s wait ;******************************************** wait: r=#(838-14-12-8)/12 ; call(14), ret(12), mov(8) waitct: ; set 100- m s. dbnz b,$waitct ; 1 instruction, 12 clocks ret ;******************************************** ;* starting edge detection mode setting ;******************************************** s_m0set: to_cnt=#0 selmod=#0 ; starting edge detection mode intm0=#00000000b ; intp0 falling edge ret ;******************************************** ;* error data detection mode setting ;******************************************** s_m5set: rptct=#16 ; counter for 250-ms measurement selmod=#5 ; end of data input mode rmendct=#2 ; counter to verify no input ret
101 chapter 6 8-bit timer/event counter application chapter 6 8-bit timer/event counter application the 8-bit timer/event counter in the 78k/0 series has the three functions of interval timer, external event counter, and square-wave output. in addition, the 8-bit timer/event counter has two on-chip channels. moreover, they can be used as a 16-bit timer/event counter by connecting them in cascade. the 8-bit timer/event counter requires the setting of the following five registers: ? timer clock selection register 1 (tcl1) ? 8-bit timer mode control register (tmc1) ? 8-bit timer output control register (toc1) ? port mode register 3 (pm3) ? port 3 (p3)
102 78k/0 series application note figure 6-1. format of timer clock selection register 1 caution when tcl1 will be rewritten with data other than identical data, rewrite after temporarily stopping the timer. remarks 1. f x : main system clock oscillation fre- quency 2. ti1: input pin of 8-bit timer register 1 3. ti2: input pin of 8-bit timer register 2 4. the values in parentheses apply to op- eration with f x = 5.0 mhz. 7 tcl17 6 tcl16 5 tcl15 4 tcl14 3 tcl13 2 tcl12 1 tcl11 0 tcl10 symbol tcl1 address ff41h at reset 00h r/w r/w tcl13 0 0 0 0 0 1 1 1 1 1 1 1 1 tcl12 0 0 1 1 1 0 0 0 0 1 1 1 1 tcl11 0 0 0 1 1 0 0 1 1 0 0 1 1 count clock selection of 8-bit timer register 1 falling edge at ti1 rising edge at ti1 f x /2 (2.5 mhz) f x /2 2 (1.25 mhz) f x /2 3 (625 khz) f x /2 4 (313 khz) f x /2 5 (156 khz) f x /2 6 (78.1 khz) f x /2 7 (39.1 khz) f x /2 8 (19.5 khz) f x /2 9 (9.8 khz) f x /2 10 (4.9 khz) f x /2 12 (1.2 khz) setting prohibited tcl10 0 1 1 0 1 0 1 0 1 0 1 0 1 other than the above tcl17 0 0 0 0 0 1 1 1 1 1 1 1 1 tcl16 0 0 1 1 1 0 0 0 0 1 1 1 1 tcl15 0 0 0 1 1 0 0 1 1 0 0 1 1 count clock selection of 8-bit timer register 2 falling edge at ti2 rising edge at ti2 f x /2 (2.5 mhz) f x /2 2 (1.25 mhz) f x /2 3 (625 khz) f x /2 4 (313 khz) f x /2 5 (156 khz) f x /2 6 (78.1 khz) f x /2 7 (39.1 khz) f x /2 8 (19.5 khz) f x /2 9 (9.8 khz) f x /2 10 (4.9 khz) f x /2 12 (1.2 khz) setting prohibited tcl14 0 1 1 0 1 0 1 0 1 0 1 0 1 other than the above
103 chapter 6 8-bit timer/event counter application figure 6-2. format of the 8-bit timer mode control register cautions 1. switch the operating mode after stopping timer operation. 2. when used as a 16-bit timer register, use tce1 to enable or stop operation. 7 0 6 0 5 0 4 0 3 0 2 tmc12 1 tce2 0 tce1 symbol tmc1 address ff49h at reset 00h r/w r/w tce1 0 1 controlling the operation of 8-bit timer register 1 stop operation (tm1 is cleared to 0) operation enabled tmc12 0 1 selection of the operating mode 8-bit timer register x 2-channel mode (tm1, tm2) 16-bit timer register x 1-channel mode (tms) tce2 0 1 controlling the operation of 8-bit timer register 2 stop operation (tm2 is cleared to 0) operation enabled
104 78k/0 series application note figure 6-3. format of the 8-bit timer output control register cautions 1. always set toc1 after stopping timer operation. 2. when lvs1, lvs2, lvr1, and lvr2 are read out after data were set, 0?s are read out. 7 lvs2 6 lvr2 5 toc15 4 toe2 3 lvs1 2 lvr1 1 toc11 0 toe1 symbol toc1 address ff4fh at reset 00h r/w r/w toe1 0 1 output control of 8-bit timer/event counter 1 output prohibited (port mode) output enabled toc11 0 1 control of timer output flip-flop of 8-bit timer/event counter 1 inversion disabled inversion enabled lvs1 0 0 1 1 lvr1 0 1 0 1 setting the state of the timer output flip-flop of 8-bit timer/event counter 1 do not change. reset the timer output flip-flop (0) set the timer output flip-flop (1) setting prohibited toe2 0 1 output control of 8-bit timer/event counter 2 output prohibited (port mode) output enabled toc15 0 1 control of timer output flip-flop of 8-bit timer/event counter 2 inversion disabled inversion enabled lvs2 0 0 1 1 lvr2 0 1 0 1 setting the state of the timer output flip-flop of 8-bit timer/event counter 2 do not change reset the timer output flip-flop (0) set the timer output flip-flop (1) setting prohibited
105 chapter 6 8-bit timer/event counter application figure 6-4. format of port mode register 3 caution when the p31/to1 and p32/to2 pins are used for timer output, do not only set the output latches of pm31 and pm32 to 0, also set the output latches of p31 and p32 to 0. 7 pm37 6 pm36 5 pm35 4 pm34 3 pm33 2 pm32 1 pm31 0 pm30 symbol pm3 address ff23h at reset ffh r/w r/w pm3n 0 1 selection of the i/o mode of pin p3n (n=0 to 7) output mode (output buffer on) input mode (output buffer off)
106 78k/0 series application note 6.1 setting the interval timer when the interval timer is used, the operating mode of the 8-bit timer is set by the 8-bit timer mode control register (tmc1) and the interval time is set by timer clock selection register 1 (tcl1). the values of the compare registers (cr10, cr20) are set based on the interval time and count clock. the setting time is determined in the form shown below. setting-time = (value-in-compare-register + 1) x count-clock-period the setting time can be determined in a similar manner even when used as an 8-bit timer or as a 16- bit timer. however, when used as a 16-bit timer, the count clock becomes the value selected in bits 0 to 3 (tcl10 to tcl13) in tcl1. next, examples of each mode of the 8-bit timer and 16-bit timer are illustrated. figure 6-5. count timing of an 8-bit timer count clock tm1, tm2 inttm1, inttm2 to1 n? n? n 00 01 02 n? n? n
107 chapter 6 8-bit timer/event counter application 6.1.1 setting an 8-bit timer this example describes using 8-bit timer 2 and setting the interval times of 500 m s and 100 ms. (a) for the 500- m s interval <1> tmc1 setting select the 8-bit timer register x 2-channel mode and enable 8-bit timer 2 operation. <2> tcl1 setting a setting above 500 m s is possible. select the highest possible resolution of f x /2 4 . <3> cr20 setting 500 m s = (n + 1) x 1 4.19 mhz/2 4 n = 500 m s x 4.19 mhz/2 4 C 1 = 130 (1) program listing tcl1 = #10001000b ; select f x /2 4 for the count clock. cr20 = #130 tmc1 = #00000010b . .
108 78k/0 series application note (b) for the 100-ms interval <1> tmc1 setting select the 8-bit timer register x 2-channel mode and enable 8-bit timer 2 operation. <2> tcl1 setting a setting above 100 ms is possible. select the highest possible resolution of f x /2 12 . <3> cr20 setting 100 ms = (n + 1) x 1 4.19 mhz/2 12 n = 100 ms x 4.19 mhz/2 12 C 1 = 101 (1) program listing tcl1 = #11111111b ; select count clock f x /2 12 . cr20 = #101 tmc1 = #00000010b . .
109 chapter 6 8-bit timer/event counter application 6.1.2 setting the 16-bit timer this example describes connecting 8-bit timer 1 and 8-bit timer 2 in a cascade and setting the interval times of 500 ms and 10 s. (a) for the 500-ms interval <1> tmc1 setting in the 16-bit timer register x 1-channel mode, enable the operations of 8-bit timers 1 and 2. <2> tcl1 setting a setting above 500 ms is possible. select the highest possible resolution of f x /2 5 . <3> cr10 and cr20 settings 500 ms = n + 1 4.19 mhz/2 5 n = 500 ms x 4.19 mhz/2 5 C 1 = 65468 = ff6ch cr10 = 6ch, cr20 = ffh (1) program listing tcl1 = #00001001b cr10 = #06ch ; set 65468 in cr10 and cr20. cr20 = #0ffh ; cr10 = 6ch, cr20 = ffh tmc1 = #00000111b . .
110 78k/0 series application note (b) for the 10-s interval <1> tmc1 setting in the 16-bit timer register x 1-channel mode, enable the operations of 8-bit timers 1 and 2. <2> tcl1 setting a setting above 10 s is possible. select the highest possible resolution of f x /2 10 . <3> cr10 and cr20 settings 10 s = n + 1 4.19 mhz/2 10 n = 10 s x 4.19 mhz/2 10 C 1 = 40959 = 9fffh cr10 = ffh, cr20 = 9fh (1) program listing tcl1 = #00001110b cr10 = #0ffh ; set 40959 in cr10 and cr20. cr20 = #9fh ; cr10 = ffh, cr20 = 9fh tmc1 = #00000111b . .
111 chapter 6 8-bit timer/event counter application 6.2 musical scale generation in this example, the square-wave output (p31/to1) function of 8-bit timer/event counter 1 is used and a program is illustrated that supplies pulses to an externally attached buzzer to generate a musical scale. figure 6-6. musical scale generation circuit the output frequency from pin p31/to1 is set in the count clock and the compare register. in this example, because the center of the frequencies of the musical scale is set in the range of 523 hz and 1046 hz, f x /2 5 is selected for the count clock. table 6-1 lists the settings of the musical scale, compare registers, and frequencies of the pulses to be output. however, because the timer output matches the compare register twice and is created in one period, the interval setting is in one-half of a period. figure 6-7. timer output and interval interval timer output period cr10 matching interval v dd p31/to1 PD78044F
112 78k/0 series application note in the temporal length of the sound, the interval time is set in the 8-bit timer/event counter 2. the number of interrupts are counted and the output time is determined. in this example, 8-bit timer/event counter 2 is set to 20 ms. table 6-1. musical scale and frequencies musical scale musical scale frequencies (hz) compare register value output frequency (hz) c 523.25 124 524.3 d 587.33 111 585.1 e 659.25 98 662.0 f 698.46 93 697.2 g 783.98 83 780.2 a 880.00 73 885.6 b 987.77 65 993.0 c 1046.5 62 1040 the format of the data table in this program is shown below. table: db musical scale data 1, sound length data 1 db musical scale data 2, sound length data 2 db musical scale data n, sound length data n db 0, 0 when there is a rest, musical scale data is set to 0. at the end of data, the length of the sound data is set to 0. example count of the 8-bit timer/event counter 2 when the sound is output for one second count = 1 s/20 ms = 50 (data for the count is set to 50.) data in this program illustrates an example where c, d, e, ..., c are each output in order for one second. . . . . . .
113 chapter 6 8-bit timer/event counter application (1) package description mldy: subroutine name of the musical scale generation program bank 0: a, b, hl name use attribute byte point save the pointer of table data. saddr 1 lng count the length of the sound data. 1 level, 3 bytes ? 8-bit timer/event counters 1 and 2 ? p31/to1 ? subroutine mldy is set. ? interrupts enabled ? call subroutine mldy. (2) use example extrn mldy call !mldy ei . . .
114 78k/0 series application note (3) spd chart select register bank 0 decrement the length of the sound data (lng) if : at the end of the output time then set sound data in the compare register of timer 1 disable to1 output of timer 1 else set p31/to1 to the output mode. set the pointer (point) to the reference table to 0. set the length of the sound data (lng) to the initial data of 1. 8-bit timer/event counter 1 is set to the output mode. 8-bit timer/event counter 2 is set to 20 ms. 8-bit timer 2 interrupt enabled. mldy inttm2 then look up sound data indicated by the pointer if : sound data 1 no-sound data look up the length data of the sound if : length of sound data 1 end of musical scale generation data then set the length of sound data timer 2 interrupt disabled else timer 2 operation stopped
115 chapter 6 8-bit timer/event counter application (4) program listing public mldy vetm2 cseg at 18h dw inttm2 ; setting the vector address of 8-bit timer/event counter 2 ml_dat dseg saddr point: ds 1 ; pointer to table data lng: ds 1 ; length data of sound ;************************************************ ;* musical scale generation initialization ;************************************************ ml_seg cseg mldy: clr1 pm3.1 ; set bit 1 of port 3 in output mode. point=#0 ; initial setting of the pointer lng=#1 toc1=#00000011b ; set to the to1 output mode. tcl1=#11011001b cr20=#163 ; set timer 2 to 20 ms. tmc1=#00000010b ; timer 2 operation enabled clr1 tmmk2 ; timer 2 interrupt enabled ret $eject
116 78k/0 series application note ;***************************************** ;* setting musical scale generation ;***************************************** tm2_seg cseg inttm2: sel rb0 lng-- if(lng==#0) b=point (a) hl=#table ; setting the start address of the table a=[hl+b] if(a!=#0) clr1 tce1 ; sound data setting cr10=a set1 toe1 set1 tce1 else clr1 toe1 endif b++ ; increment pointer. a=[hl+b] ; read the length data of the sound if(a!=#0) ; is the sound being output? lng=a ; sound length data setting b++ point=b (a) else set1 tmmk2 ; timer 2 interrupt disabled clr1 tce2 ; timer 2 operation stopped endif endif reti ;***************************************** ;* musical scale data table ;***************************************** table: db 124,50 ; c db 111,50 ; d db 98,50 ; e db 93,50 ; f db 83,50 ; g db 73,50 ; a db 65,50 ; b db 62,50 ; c db 00,00 ; end
117 chapter 7 watch timer application chapter 7 watch timer application the 78k/0 series watch timer has a watch timer function that uses as the source signal the main system clock or the subsystem clock and overflows every 0.5 seconds, and an interval timer function capable of setting six types of basic times. these two functions can be used at the same time. the watch timer is set by timer clock selection register 2 (tcl2) and watch timer mode control register (tmc2). figure 7-1. format of timer clock selection register 2 note when a main system clock at 1.25 mhz or lower and an fip controller/driver are used simultaneously, select f x /2 8 as the count clock for the watch timer. caution when tcl2 will be rewritten with data other than identical data, rewrite after temporarily stopping timer operation. 7 tcl27 6 tcl26 5 tcl25 4 tcl24 3 0 2 tcl22 1 tcl21 0 tcl20 symbol tcl2 address ff42h at reset 00h r/w r/w tcl22 0 0 0 0 1 1 1 1 tcl21 0 0 1 1 0 0 1 1 tcl20 0 1 0 1 0 1 0 1 tcl24 0 1 count clock selection for the watch timer note f x /2 8 (19.5 khz) f xt (32.768 khz) tcl27 0 1 1 1 1 tcl26 x 0 0 1 1 tcl25 x 0 1 0 1 f x /2 10 (4.9 khz) f x /2 11 (2.4 khz) f x /2 12 (1.2 khz) setting prohibited selection of the buzzer output frequency buzzer output prohibited count clock selection f x /2 3 (625 khz) f x /2 4 (313 khz) f x /2 5 (156 khz) f x /2 6 (78.1 khz) f x /2 7 (39.1 khz) f x /2 8 (19.5 khz) f x /2 9 (9.8 khz) f x /2 11 (2.4 khz) watchdog timer mode f x /2 4 (313 khz) f x /2 5 (156 khz) f x /2 6 (78.1 khz) f x /2 7 (39.1 khz) f x /2 8 (19.5 khz) f x /2 9 (9.8 khz) f x /2 10 (4.9 khz) f x /2 12 (1.2 khz) interval timer mode
118 78k/0 series application note remarks 1. f x : main system clock oscillation frequency 2. f xt : subsystem clock oscillation frequency 3. x : dont care 4. the values in parentheses apply to operation with f x = 5.0 mhz or f xt = 32.768 khz. figure 7-2. format of the watch timer mode control register caution when a watch timer is used, do not frequently clear the prescaler. remarks 1. f w : clock frequency of the watch timer (f x /2 8 or f xt ) 2. the values in parentheses apply to operation with f w = 32.768 khz. other than the above 7 0 6 tmc26 5 tmc25 4 tmc24 3 tmc23 2 tmc22 1 tmc21 0 tmc20 symbol tmc2 address ff4ah at reset 00h r/w r/w tmc26 0 0 0 0 1 1 tmc25 0 0 1 1 0 0 tmc24 0 1 0 1 0 1 selection of the prescaler interval time 2 4 /f w (488 s) 2 5 /f w (977 s) 2 6 /f w (1.95 ms) 2 7 /f w (3.91 ms) 2 8 /f w (7.81 ms) 2 9 /f w (15.6 ms) setting prohibited tmc21 0 1 control of prescaler operation note clear after stopping operation operation enabled tmc23 0 1 0 1 tmc20 0 1 selection of the set time for the watch flag 2 14 /f w (0.5 s) 2 13 /f w (0.25 s) 2 5 /f w (977 s) 2 4 /f w (488 s) tmc22 0 1 control operation of a 5-bit counter clear after stopping operation operation enabled
119 chapter 7 watch timer application 7.1 watch and led display program an example using the watch timer is illustrated for a time count using the 0.5-second overflow and led dynamic display using the 1.95-ms interval. when the time count tests the overflow flag each time a subroutine is called. when it is set, count up processing of seconds is performed. because overflow is generated at 0.5 s, when there are 120 counts, 1 minute is counted. the overflow test is performed at 1.95-ms intervals in order not to lose data. the watch display of this program is a 24-hour display. minute data and hour data are separately stored in memory as the high-order and low-order digits. figure 7-3. schematic of watch data seconds data minutes data hours data low order 0-9 high order 0-5 low order 0-9 high order 0-2 0-120
120 78k/0 series application note an led dynamic display is a four-digit display that switches the display digits in each 1.95-ms interval. in this example, the high-order four bits of p3 in the digit signal selects p12 where the leds in the segment signal can be driven directly. the led display displays the digits shown in the display digit area (digct) of the led display area (leddp). also, when the digit signal switches, switching is performed after the segment signal is turned off in order not to shift neighboring digit displays. figure 7-4. led display timing figure 7-5. example circuit of the watch timer p34 p35 p36 p37 segment signal off port 12 digct 012301230123 7-segment led x 4 PD78044F p120 p127 p37 p36 p35 p34
121 chapter 7 watch timer application (1) package description secd : area storing seconds data mindp : area storing minutes data hourdp : area storing hours data leddp : led display area bank 0: ax, b, hl name use attribute byte mindp minutes data storage saddrp 2 hourdp hours data storage secd seconds data storage 1 digct led display digit data storage leddp led display data 4 ? watch timer ? p34-37 ? p12 ? watch operation of 0.5 s, interval of 1.95 ms tmc2 = #00100110b ? watch timer interrupt enabled tmmk3 = 0 startup is by the interval timer interrupt request of the watch timer. (2) use example extrn mindp,hourdp,secd,leddp tmc2 = #00100110b ; 0.5-s watch operation, 1.95-ms interval clr1 tmmk3 ; watch timer interrupt enabled ei
122 78k/0 series application note (3) spd chart select register bank 0 time count time leds display leddsp inttm3 turn segment signal off if : digit counter (digct) = 0 leddsp then initial setting of the digit signal shift the digit signal to the one bit in the high-order direction else the segment signal that displays the digit counter is output increment the digit counter time if : the watch timer interrupt request flag is set then increment seconds counter if : seconds counter=120 then set the seconds counter to 0 minutes (low order) counter increment if : minutes (low order) counter=10 then set minutes (low order) counter to 0 increment minutes (high order) counter if : minutes (high order) counter=6 then set the minutes (high order) counter to 0 increment hours (high order) counter if : time data 1 0204h then if : hours (low order) counter=10 then set the hours (low order) counter to 0 increment the hours (high order) counter else set the hours counter to 0
123 chapter 7 watch timer application (4) program listing public hourdp,mindp,secd,leddp wt_datp dseg saddrp mindp: ds 2 ; area storing minutes data hourdp: ds 2 ; area storing hours data secd: ds 1 ; area storing seconds data digct: ds 1 ; leds display digit area leddp: ds 4 ; leds display area vetm3 cseg at 12h dw inttm3 ; setting the vector address of the watch timer ;************************************** ;* interval interrupt processing ;************************************** tm3_seg cseg inttm3: sel rb0 call !time call !leddpsp reti
124 78k/0 series application note ;******************** ;* led display ;******************** leddpsp: p12=#0ffh ; segment output off digct&=#00000011b ; adjustment of digit counter (0 to 3) if(digct==#0) a=p3 a&=#00001111b ; initial setting of digit signal (high-order 4 bits) a!=#00010000b p3=a else a=p3 a&=#11110000b ; shift high-order 4 bits. x=a a=p3 a+=x p3=a endif b=digct (a) ; address setting of display data hl=#leddp ; start address of the display area b=[hl+b] (a) ; display data setting hl=#segdt ; change to segment data. p12=[hl+b] (a) ; segment signal output digct++ ret segdt: db 11000000b ; 0 db 11111001b ; 1 db 10100100b ; 2 db 10110000b ; 3 db 10011001b ; 4 db 10010010b ; 5 db 10000010b ; 6 db 11111000b ; 7 db 10000000b ; 8 db 10010000b ; 9 db 10001000b ; a db 10000011b ; b db 11000110b ; c db 10100001b ; d db 10000110b ; e db 10001110b ; f $eject
125 chapter 7 watch timer application ;*********************** ;* watch count up ;*********************** time: if_bit(wtif) ; 0.5-s test clr1 wtif secd++ ; 120 = 60 s/0.5 if(secd==#120) secd=#0 (mindp+0)++ ; increment low-order part of minutes. if((mindp+0)==#10) ; digit carry (mindp+0)=#0 (mindp+1)++ ; increment high-order part of minutes. if(mindp+1==#6) ; digit carry (mindp+1)=#0 (hourdp+0)++ if(hourdp!=#0204h) (ax) ; is hour data 24? if((hourdp+0)==#10) ; digit carry (hourdp+0)=#0 (hourdp+1)++ endif else hourdp=#0000h endif endif endif endif endif ret
126 78k/0 series application note [memo]
127 chapter 8 serial interface application chapter 8 serial interface application table 8-1 lists the serial interfaces of the 78k/0 series. table 8-1. available serial interface channels in each subseries serial interface channel 0 channel 1 channel 3 configuration 3-wire 2-wire sbi 3-wire 3-wire mode 3-wire with automatic transmission/ subseries reception function m PD78044F o o o o o x m pd78044h x x x o x x m pd780208 o o o o o x m pd780228 x x x x x o remark o: function available x: function not available the serial interface requires the setting of the following registers. table 8-2. serial interface registers serial interface registers to be used channel 0 ? timer clock selection register (tcl3) ? serial operating mode register 0 (csim0) ? serial bus interface control register (sbic) ? interrupt timing specification register (sint) channel 1 ? timer clock selection register (tcl3) ? serial operating mode register 1 (csim1) ? automatic data transmit/receive control register (adtc) ? automatic data transmit/receive interval setting register (adti) remark this chapter describes only the register formats and sample applications for serial interface channels 0 and 1. for details of the register format for channel 3, refer to the m pd780228 subseries user?s manual (u12012e). * *
128 78k/0 series application note figure 8-1. format of timer clock selection register 3 ( m PD78044F and m pd780208 subseries) caution when data other than the same data is rewritten into tcl3, rewrite after temporarily stopping timer operation. remarks 1. f x : main system clock oscillation frequency 2. the values in parentheses apply to operation with f x = 5.0 mhz. 7 tcl37 6 tcl36 5 tcl35 4 tcl34 3 tcl33 2 tcl32 1 tcl31 0 tcl30 symbol tcl3 address ff43h at reset 88h r/w r/w tcl33 0 0 1 1 1 1 1 1 tcl32 1 1 0 0 0 0 1 1 tcl31 1 1 0 0 1 1 0 0 f x /2 2 (1.25 mhz) f x /2 3 (625 khz) f x /2 4 (313 khz) f x /2 5 (156 khz) f x /2 6 (78.1 khz) f x /2 7 (39.1 khz) f x /2 8 (19.5 khz) f x /2 9 (9.8 khz) tcl30 0 1 0 1 0 1 0 1 selection of serial clock for serial interface channel 0 other than the above setting prohibited tcl37 0 0 1 1 1 1 1 1 tcl36 1 1 0 0 0 0 1 1 tcl35 1 1 0 0 1 1 0 0 f x /2 2 (1.25 mhz) f x /2 3 (625 khz) f x /2 4 (313 khz) f x /2 5 (156 khz) f x /2 6 (78.1 khz) f x /2 7 (39.1 khz) f x /2 8 (19.5 khz) f x /2 9 (9.8 khz) tcl34 0 1 0 1 0 1 0 1 selection of serial clock for serial interface channel 1 other than the above setting prohibited
129 chapter 8 serial interface application figure 8-2. format of timer clock selection register 3 ( m pd78044h subseries) note bits 0 to 3 are read-only. when bits 0 to 3 are read, the operation will become unpredictable. caution when data other than the same data is rewritten into tcl3, rewrite after temporarily stopping timer operation. remarks 1. f x : main system clock oscillation frequency 2. the values in parentheses apply to operation with f x = 5.0 mhz. 7 tcl37 6 tcl36 5 tcl35 4 tcl34 3 0 2 0 1 0 0 0 symbol tcl3 address ff43h at reset 88h r/w r/w note tcl37 0 0 1 1 1 1 1 1 tcl36 1 1 0 0 0 0 1 1 tcl35 1 1 0 0 1 1 0 0 f x /2 2 (1.25 mhz) f x /2 3 (625 khz) f x /2 4 (313 khz) f x /2 5 (156 khz) f x /2 6 (78.1 khz) f x /2 7 (39.1 khz) f x /2 8 (19.5 khz) f x /2 9 (9.8 khz) tcl34 0 1 0 1 0 1 0 1 selection of serial clock for serial interface channel 1 other than the above setting prohibited *
130 78k/0 series application note figure 8-3. format of serial operating mode register 0 (only for the m PD78044F and m pd780208 subseries) (1/2) notes 1. bit 6 (coi) is read-only. 2. when only transmission is performed, this pin can be used as p25 (cmos input). 3. this pin can be used for a port function. 4. when the wakeup function is used (wup = 1), set bit 5 (sic) of the interrupt timing specification register (sint) to 0. caution the operating mode (3-wire serial i/o, 2-wire serial i/o, or sbi mode) must not be changed while serial interface channel 0 is enabled. to change the operating mode, temporarily stop serial operation beforehand. remark x : dont care pmxx : port mode register pxx : port output latch * * csim0 symbol address at reset r/w ff60h 00h r/w note 1 r/w si0/sb0/p25 pin function so0/sb1/p26 pin function sck0/p27 pin function ? ? ? r/w wakeup function control note 4 an interrupt request signal is issued at each serial transfer in all of the modes. when the address received after the bus release in the sbi mode (when cmdd = reld = 1) matches the data in the slave address register, an interrupt request signal is issued. sck0 (cmos i/o) ? ? ? ? ? ? si0 note 2 (input) ? ? ? ? ? ? msb lsb msb msb operating mode 3-wire serial i/o mode wup 0 1 p27 1 1 1 1 1 pm27 0 0 0 0 0 p26 0 0 0 pm26 p25 pm25 csim 02 0 1 0 1 0 1 x 0 1 0 1 1 note 3 x 0 0 0 note 3 x x 0 0 1 0 0 csim 03 csim 04 r/w input clock from the outside to pin sck0 x 0 1 0 1 1 csim 00 csim 01 clock selection for serial interface channel 0 2 3 40 1 765 csim 02 csim 03 csim 04 csim 00 csim 01 csie 0 coi wup output of the 8-bit timer register 2 (tm2) clock specified by bits 0 to 3 of the timer clock selection register 3 (tcl3) first bit so0 (cmos output) note 3 x note 3 x note 3 x note 3 x note 3 x note 3 x sbi mode 2-wire serial i/o mode p25 (cmos i/o) sb0 n-channel open drain i/o p25 (cmos i/o) sb0 n-channel open drain i/o sb1 n-channel open drain i/o p26 (cmos i/o) sb1 n-channel open drain i/o p26 (cmos i/o) sck0 (cmos i/o) sck0 n-channel open drain i/o
131 chapter 8 serial interface application figure 8-3. format of serial operating mode register 0 (only for the m PD78044F and m pd780208 subseries) (2/2) note when csie0 = 0, coi becomes 0. caution the operating mode (3-wire serial i/o, 2-wire serial i/o, or sbi mode) must not be changed while serial interface channel 0 is enabled. to change the operating mode, temporarily stop serial operation beforehand. r/w control of serial interface channel 0 operation stop operation enable operation r slave address comparison result flag note data in the slave address register and data in serial i/o shift register 0 do not match. data in the slave address register and data in serial i/o shift register 0 match. csie0 0 1 coi 0 1 *
132 78k/0 series application note figure 8-4. format of the serial operating mode register 1 ( m PD78044F and m pd780208 subseries) notes 1. when an external clock input is selected and csim11 is 0, set bits 2 and 1(strb and busy1) of the automatic data transmit/receive control register (adtc) to 0. 2. this can be used for a port function. 3. when only transmission is performed, this can be used as p20. set bit 7 (re) of adtc to 0. remark x : dont care pmxx : port mode register pxx : port output latch csim1 symbol address at reset r/w ff68h 00h r/w ate 0 1 p22 pm22 x 1 p21 1 0 pm21 p20 pm20 x 0 1 0 10 0 note 2 x note 2 x csim 11 csie 1 external clock input note 1 to sck1 pin output of 8-bit timer register 2 (tm2) clock set by bits 4 to 7 of timer clock selection register 3 (tcl3) x 0 1 0 1 1 csim 10 csim 11 clock selection for serial interface channel 1 2 3 40 1 765 csim 10 csim 11 csie 1 dir ate 0 0 0 first bit msb lsb dir 0 1 si1 pin function si1/p20 (input) so1 pin function so1 (cmos output) note 2 x note 3 x note 3 1 note 2 x note 2 x note 2 x si1/p20 pin function so1/p21 pin function clear shift register 1 operation control of serial clock counter operation stop operation p20 (cmos i/o) selection of operating mode of serial interface channel 1 3-wire serial i/o mode 3-wire serial i/o mode with automatic transmit/receive function sck1/p22 pin function p21 (cmos i/o) p22 (cmos i/o) count operation enable operation si1 note 3 (input) so1 (cmos output) sck1 (input) sck1 (cmos output) *
133 chapter 8 serial interface application figure 8-5. format of the serial operating mode register 1 ( m pd78044h subseries) notes 1. always set to 0. 2. this can be used for a port function. 3. when only transmission is performed, this can be used as p20 (cmos i/o). remark x : dont care pmxx : port mode register pxx : port output latch csim1 symbol address at reset r/w ff68h 00h r/w p22 pm22 x 1 p21 1 0 pm21 p20 pm20 x 0 1 0 10 0 note 2 x note 2 x csim 11 csie 1 external clock input to sck1 pin output of 8-bit timer register 2 (tm2) clock set by bits 4 to 7 of timer clock selection register 3 (tcl3) x 0 1 0 1 1 csim 10 csim 11 clock selection for serial interface channel 1 2 3 40 1 765 csim 10 csim 11 csie 1 dir 0 note 1 000 first bit msb lsb dir 0 1 si1 pin function si1/p20 (input) so1 pin function so1 (cmos output) note 2 x note 3 x note 3 1 note 2 x note 2 x note 2 x si1/p20 pin function so1/p21 pin function clear shift register 1 operation control of serial clock counter operation stop operation p20 (cmos i/o) sck1/p22 pin function p21 (cmos i/o) p22 (cmos i/o) count operation enable operation si1 note 3 (input) so1 (cmos output) sck1 (input) sck1 (cmos output) *
134 78k/0 series application note figure 8-6. format of the interrupt timing setting register (only for the m PD78044F and m d780208 subseries) notes 1. bit 6 (cld) is read-only. 2. when the wakeup function is used, set sic to 0. 3. when csie0 = 0, cld becomes 0. caution always set bits 0 to 3 to 0. remark sva : slave address register csiif0 : interrupt request flag which corresponds to intcsi0 csie0 : bit 7 of serial operating mode register 0 (csim0) 7 0 6 cld 5 sic 4 svam 3 0 2 0 1 0 0 0 symbol sint address ff63h at reset 00h svam 0 1 sva bits used as the slave address bits 0 to 7 bits 1 to 7 sic 0 1 selection of the cause of the intcsi0 interrupt note 2 set csiif0 at the end of a transfer in serial interface channel 0. set csiif0 at the end of a transfer in serial interface channel 0 or when a bus release is detected. cld 0 1 level of sck0/p27 pin note 3 low level high level r/w r/w note 1 r/w r/w r
135 chapter 8 serial interface application figure 8-7. format of the serial bus interface control register (only for the m PD78044F and m pd780208 subseries) (1/2) r/w relt this is used to output the bus release signal. the so latch is set (1) by relt = 1. after setting the so latch, this bit is automatically cleared (0). in addition, it is cleared (0) when csie0 = 0. r/w cmdt this is used for command signal output. the so latch is cleared (0) by cmdt = 1. after clearing the so latch, this bit is automatically cleared (0). in addition, it is cleared (0) when csie0 = 0. r reld bus release detection clearing conditions (reld = 0) setting conditions (reld = 1) ? when a start transfer instruction is executed ? when a bus release signal (rel) is detected ? when the values in sio0 and sva do not match while receiving an address ? when csie0 = 0 ? when reset is input r cmdd command detection clearing conditions (cmdd = 0) setting conditions (cmdd = 1) ? when a start transfer instruction is executed ? when a command signal (cmd) is detected ? when a bus release signal (rel) is detected ? when csie0 = 0 ? when reset is input r/w ackt the acknowledge signal is output synchronized to the falling edge of the sck0 clock immediately after the execution of the instruction that is set (1). after the output, this bit is automatically cleared (0). in addition, when starting the transfer in the serial interface and csie0 = 0, this bit is also cleared (0). note bits 2, 3, and 6 (reld, cmdd, ackd) are read-only. remark csie0: bit 7 of serial operating mode register 0 (csim0) 7 bsye 6 ackd 5 acke 4 ackt 3 cmdd 2 reld 1 cmdt 0 relt symbol sbic address ff61h at reset 00h r/w r/w note
136 78k/0 series application note figure 8-7. format of the serial bus interface control register (only for the m PD78044F and m pd780208 subseries) (2/2) r/w acke acknowledge signal output control 0 automatic output of the acknowledge signal is disabled. (output by ackt is possible.) 1 before the end of transfer the acknowledge signal is output synchronized to the falling edge of the ninth sck0 clock (automatically output by acke = 1). after the transfer ends the acknowledge signal is output synchronized to the falling edge of the sck0 clock immediately after the execution of the instruction that is set (1) (automati- cally output by acke = 1). however, after the acknowledge signal is output, this is not automatically cleared (0). r ackd acknowledge detection clearing conditions (ackd = 0) setting conditions (ackd = 1) ? when a falling edge of the sck0 clock occurs ? when the acknowledge signal (ack) is detected at immediately after the busy mode was released after the rising edge of the sck0 clock after the transfer executing a start transfer instruction ends ? when csie0 = 0 ? when reset is input r/w bsye note control of synchronous busy signal output 0 the output of the busy signal is disabled synchronous to the falling edge of the sck0 clock immediately after executing the instruction that is cleared (0). 1 the busy signal is output starting at the falling edge of the sck0 clock following the acknowledge signal. note the busy mode can be released at the start of transfer in the serial interface. however, the bsye flag is not cleared to 0. remark csie0 : bit 7 of serial operating mode register 0 (csim0)
137 chapter 8 serial interface application figure 8-8. format of the automatic data transmit/receive control register (only for the m PD78044F and m pd780208 subseries) notes 1. bits 3 and 4 (trf, err) are read-only. 2. make the decision on the end of automatic transmit/receive based on trf and not on csiif1 (interrupt request flag). (continued on the next page) 7 re 6 arld 5 erce 4 err 3 trf 2 strb 1 busy1 0 busy0 symbol adtc address ff69h at reset 00h busy1 0 1 1 busy input control busy input is not used. busy input enabled (active high) busy input enabled (active low) busy0 x 0 1 strb 0 1 strobe output control strobe output disabled strobe output enabled 0 detect the end of an automatic transmit/receive. (when interrupting automatic transmit/receive or when arld = 0, this bit becomes 0.) r/w r/w note 1 r/w r/w r err error detection of the automatic transmit/receive function r erce control of the error checking of the automatic transmit/receive function r/w r/w re receive control of the automatic transmit/receive function r/w trf status of the automatic transmit/receive function note 2 1 during automatic transmit/receive (by writing to sio1, this becomes 1.) error checking disabled during automatic transmit/receive 0 arld selection of the operating mode of the automatic transmit/receive function single-shot mode repeat mode 0 1 no error during automatic transmit/receive (by writing to sio1, this bit becomes 0.) error present during automatic transmit/receive error checking enabled during automatic transmit/receive (only when busy1 = 1) reception disabled reception enabled 0 1 0 1 1
138 78k/0 series application note caution when bit 1 (csim11) of serial operating mode register 1 (csim1) is set to 0 and the external clock input is selected, set strb and busy1 in adtc to 0. remark x: dont care figure 8-9. format of the automatic data transmit/receive interval setting register (only for the m PD78044F and m pd780208 subseries) (1/2) adti7 control the interval time for data transfer 0 no control of the interval time by adti note 1 1 control of the interval time by adti (adti0 to adti4) adti4 adti3 adti2 adti1 adti0 setting the interval time for data transfer (during f x = 5.0 mhz operation) minimum value note 2 maximum value note 2 00000 36.8 m s + 0.5/f sck 40.0 m s + 1.5/f sck 00001 62.4 m s + 0.5/f sck 65.6 m s + 1.5/f sck 00010 88.0 m s + 0.5/f sck 91.2 m s + 1.5/f sck 00011 113.6 m s + 0.5/f sck 116.8 m s + 1.5/f sck 00100 139.2 m s + 0.5/f sck 142.4 m s + 1.5/f sck 00101 164.8 m s + 0.5/f sck 168.0 m s + 1.5/f sck 00110 190.4 m s + 0.5/f sck 193.6 m s + 1.5/f sck 00111 216.0 m s + 0.5/f sck 219.2 m s + 1.5/f sck 01000 241.6 m s + 0.5/f sck 244.8 m s + 1.5/f sck 01001 267.2 m s + 0.5/f sck 270.4 m s + 1.5/f sck 01010 292.8 m s + 0.5/f sck 296.0 m s + 1.5/f sck 01011 318.4 m s + 0.5/f sck 321.6 m s + 1.5/f sck 01100 344.0 m s + 0.5/f sck 347.2 m s + 1.5/f sck 01101 369.6 m s + 0.5/f sck 372.8 m s + 1.5/f sck 01110 395.2 m s + 0.5/f sck 398.4 m s + 1.5/f sck 01111 420.8 m s + 0.5/f sck 424.0 m s + 1.5/f sck (continued on the next page) 7 adti7 6 0 5 0 4 adti4 3 adti3 2 adti2 1 adti1 0 adti0 symbol adti address ff6bh at reset 00h r/w r/w
139 chapter 8 serial interface application notes 1. the interval time depends only on cpu processing. 2. errors are contained in the interval time for data transfer. the minimum and maximum values of the interval time for each data transfer are determined from the following equations (n: values set in adti0 to adti4). however, when the minimum value calculated from the following equation is less than 2/f sck , the minimum value of the interval time becomes 2/f sck . minimum value = (n + 1) x 2 7 + 56 + 0.5 f x f x f sck maximum value = (n + 1) x 2 7 + 72 + 1.5 f x f x f sck cautions 1. do not write to adti during operation of the automatic transmit-receive function. 2. always set bits 5 and 6 to 0. 3. when adti is being used to control the interval time for data transfer performed using the automatic transmission/reception function, busy control is disabled. remarks 1. f x : main system clock oscillation frequency 2. f sck : serial clock frequency *
140 78k/0 series application note figure 8-9. format of the automatic data transmit/receive interval setting register (only for the m PD78044F and m pd780208 subseries) (2/2) adti4 adti3 adti2 adti1 adti0 setting the interval time for data transfer (during f x = 5.0 mhz operation) minimum value note maximum value note 10000 446.4 m s + 0.5/f sck 449.6 m s + 1.5/f sck 10001 472.0 m s + 0.5/f sck 475.2 m s + 1.5/f sck 10010 497.6 m s + 0.5/f sck 500.8 m s + 1.5/f sck 10011 523.2 m s + 0.5/f sck 526.4 m s + 1.5/f sck 10100 548.8 m s + 0.5/f sck 552.0 m s + 1.5/f sck 10101 574.4 m s + 0.5/f sck 577.6 m s + 1.5/f sck 10110 600.0 m s + 0.5/f sck 603.2 m s + 1.5/f sck 10111 625.6 m s + 0.5/f sck 628.8 m s + 1.5/f sck 11000 651.2 m s + 0.5/f sck 654.4 m s + 1.5/f sck 11001 676.8 m s + 0.5/f sck 680.0 m s + 1.5/f sck 11010 702.4 m s + 0.5/f sck 705.6 m s + 1.5/f sck 11011 728.0 m s + 0.5/f sck 731.2 m s + 1.5/f sck 11100 753.6 m s + 0.5/f sck 756.8 m s + 1.5/f sck 11101 779.2 m s + 0.5/f sck 782.4 m s + 1.5/f sck 11110 804.8 m s + 0.5/f sck 808.0 m s + 1.5/f sck 11111 830.4 m s + 0.5/f sck 833.6 m s + 1.5/f sck note errors are contained in the interval time for data transfer. the minimum and maximum values of the interval time for each data transfer are determined from the following equations (n: values set in adti0 to adti4). however, when the minimum value calculated from the following equation is less than 2/f sck , the minimum value of the interval time becomes 2/f sck . minimum value = (n + 1) x 2 7 + 56 + 0.5 f x f x f sck maximum value = (n + 1) x 2 7 + 72 + 1.5 f x f x f sck cautions 1. do not write to adti during operation of the automatic transmit/receive func- tion. 2. always set bits 5 and 6 to 0. 3. when adti is being used to control the interval time for data transfer performed using the automatic transmission/reception function, busy control is disabled. remarks 1. f x : main system clock oscillation frequency 2. f sck : serial clock frequency 7 adti7 6 0 5 0 4 adti4 3 adti3 2 adti2 1 adti1 0 adti0 symbol adti address ff6bh at reset 00h r/w r/w *
141 chapter 8 serial interface application 8.1 interfacing with eeprom tm ( m pd6252) the m pd6252 note is a 2048-bit electrically programmable and erasable rom (eeprom). writing to and reading from the m pd6252 is performed through a 3-wire serial interface. note the m pd6252 is provided for maintenance purposes only. figure 8-10. m pd6252 pin configuration * ce ic ic gnd v dd cs scl sda 8 7 6 5 1 2 3 4
142 78k/0 series application note table 8-3. description of m pd6252 pins pin number pin name i/o function 1 ce cmos input set high during data transfer. caution do not switch to this pin from high to low during data transfer. when this pin is switched from high to low, operate in the state where the cs pin (pin 7) is set low. when pins ce and cs are both set to low levels, the standby state is entered. in the standby state, low power consumption results. 2 ic - set the ic pin to a high or low level individually using an external resistor. 3 4 gnd - ground 5 sda cmos input/ this pin is for data i/o. n-channel open- attach a pull-up resistor externally for the n-channel open-drain i/o. drain output 6 scl cmos input this is the clock input pin for data transfer. 7 cs cmos input this is the chip select pin. the m pd6252 can be operated by a high input. the read and write operations of a memory cell are not possible when at the low level. in the state where the scl pin is high, this pin changes from low to high and the signal for starting operation of the serial bus interface results. in addition, when this pin changes from high to low, the signal of the end of operation of the serial bus interface results. 8v dd - positive voltage (+5 v 10%) sda
143 chapter 8 serial interface application 8.1.1 communication in the 2-wire serial i/o mode the 3-wire system in the m pd6252 note indicates the three wires of the serial clock (scl), data (sda), and chip select (cs). consequently, except for handshakes, because the required wires in an interface become the two clock and data wires, when the 78k/0 series is used to establish an interface, the 2-wire serial i/o mode is selected. an example using the m PD78044F subseries is explained here. note the m pd6252 is provided for maintenance purposes only. figure 8-11. m pd6252 connection example table 8-4 and figure 8-12 show the commands and communication formats when the m pd6252 is read and written. sck0 sb1 p32 scl sda cs ce v dd PD78044F pd6252 v dd *
144 78k/0 series application note table 8-4. m pd6252 command list command name command operation description random write 00000000b [00h] after setting the word address (wa) (8 bits), write data is transferred. the write msb data are consecutive and a maximum of three bytes can be set. c 7 -c 0 correspondence of the word addresses wa : first data byte wa+1: second data byte wa+2: third data byte the write operation is executed during an internal write cycle after timing in which the cs pin falls from high to low. current read 10000000b [80h] the memory contents, that are specified in the word address (wa) (current msb address) when the command was set, are sent to the read data buffer. when c 7 -c 0 data is read from the sda pin, the word address (wa) is incremented for every 8 bits read out and the corresponding memory contents are sent to the read data buffer. random read 11000000b [c0h] after setting the word address (wa), a data read is executed with the set word msb address (wa) as the first address. c 7 -c 0 the difference from current read is the word address (wa) is set after the command is executed. after setting the word address (wa), the operation is identical to current read.
145 chapter 8 serial interface application figure 8-12. m pd6252 communication format (1/2) (1) random write wa input cs sda scl c 7 c 6 c 5 c 4 c 3 c 2 c 1 c 0 wb flag output wa 7 wa 6 wa 5 wa 4 wa 3 wa 2 wa 1 wa 0 d 7 d 6 d 5 d 4 d 3 d 2 d 1 d 0 byte 2 byte 3 (wa+1) (wa+2) write data input (wa) wa+1 to wa+3 in in out wb flag is held for 8 clock inputs at the scl pin. operation starts when the cs pin rises from the low to high level in the state where the scl pin is high. (sta issued) internal wa current address wa c 7 wb flag output out c 6 c 5 c 4 c 3 c 2 c 1 c 0 10000000 cs sda scl internal wa sda mode 00000000 in current address = wa out command input (wa+1) read data (wa) command input wa+1 current address d 7 d 6 d 5 d 4 d 3 d 2 d 1 d 0 d 7 d 6 d 0 d 7 d 6 d 2 d 1 d 0 (wa+2) (wa+n) wa+n+1 (2) current read wa+2 wa+n sda mode byte 1 wa holds the input value until stp is detected and then is incremented when one byte is written during the internal write cycle after stp arrives. the first data byte is written to the memory specified in wa. a write is executed when the cs pin moves from the high to low level in the state where the scl pin is high. wa becomes and holds the final write address + 1. (current address) (stp issued) operation ends when the cs pin goes from the high to low level in the state where the scl pin is high. wa becomes and holds the "final read address + 1" value. (current address) (stp issued)
146 78k/0 series application note (3) random read cs sda scl c 7 c 6 c 5 c 4 c 3 c 2 c 1 c 0 wa 7 wa 6 wa 5 wa 4 wa 3 wa 2 wa 1 wa 0 d 7 d 6 d 5 d 4 d 3 d 2 d 1 d 0 in in out internal wa sda mode current address wa 11000000 d 1 d 0 d 7 wa+n+1 out (wa) (wa+1) ... (wa+n) wa+1 wa+n wa input the wb flag is held while eight clocks are input to the scl pin. operation starts when the cs pin rises from the low to high level in the state where the scl pin is high. (sta issued) the contents of wa+1,..., wa+n are read out sequentially by reading out each byte. operation ends when the cs pin falls from the high to low level in the state where the scl pin is high. (stp issued) wa becomes and holds the "final read address+1" value. wb flag output the first byte of data read is the content of wa. figure 8-12. m pd6252 communication format (2/2)
147 chapter 8 serial interface application a program for the m pd6252 is illustrated in <1> to <5> . in this example, the number of data bytes in one write or read in the interface is fixed at one byte. in addition, when the m pd6252 is write busy (wb) while interfacing, the busy flag is set. <1> the cs pin (p32) is set to the high level to initiate the interface. <2> the write and read commands are transmitted. <3> write busy data is received. if in the state where interfacing with the m pd6252 is possible, 00h is received. when data other than 00h is received, the write busy state is judged and processing to stop communication is performed. <4> data for the command is transferred. <5> the cs pin (p32) is set low to end communication. (1) package description t3_6252 : name of m pd6252 transfer subroutine rwrite : random write command value rread : random read command value cread : current read command value wadat : word address storage area trndat : transmission data storage area rcvdat : receive data storage area cmddat : command data storage area busyfg : busy state test flag cs6252 : cs pin (p32) of m pd6252 a name use attributes bytes waadr stores the word address (before the transfer begins) saddr 1 trndat stores the transmission data (before the transfer begins) rcvdat stores the receive data (after the transfer ends) cmddat stores the command data (before the transfer begins) name use busyfg write busy state setting
148 78k/0 series application note 1 level, 3 bytes ? serial interface channel 0 ? p32 ? serial interface channel 0 settings 2-wire serial i/o mode, sb1 pin selection csim0=#10011011b ? serial clock f x /2 4 tcl3=#xxxx1000b ? sb1 latch is the high level relt=1 set the required data corresponding to command and t3_6252 is called. after returning from a subroutine, the busy flag (busyfg) is tested. when the busy flag is set, the transfer must be repeated because no transfer was performed. when in the receiving mode, after returning from a subroutine, the receive data is stored in rcvdat.
149 chapter 8 serial interface application (2) use example extrn rwrite,rread,cread extrn wadat,trndat,rcvdat,cmddat,t3_6252 extbit busyfg,cs6252 csim0=#10011011b ; 2-wire serial i/o mode and sb1 pin settings tcl3=#10011000b ; set sck0 = 262 khz. clr1 sb0 clr1 cs6252 ; set the cs pin on the m pd6252 to the low level. clr1 pm3.2 cmddat=a : : wadat=a : : trndat=a : : repeat clr1 busyfg call !t3_6252 until_bit(!busyfg) : : a=rcvdat set each data in memory. until : no write busy is present clear the busy flag. call t3_6252. read in the receive data.
150 78k/0 series application note (3) spd chart clear the busy flag. issue the start bit. transmit command. while : waiting for the end of transfer (csiif0 = 0) busy signal received while : waiting for the end of transfer (csiif0 = 0) if : not in the wb state (sio0 = 00h) t3_6252 then case : cmddat of : rwrite transfer the word address. while : waiting for the end of transfer transmit data. while : waiting for the end of transfer break of : rread transfer the word address. while : waiting for the end of transfer of : cread receive data. while : waiting for the end of transfer save the receive data in memory. else set in busy state. set busyfg. issue stop bit.
151 chapter 8 serial interface application (4) program listing public rwrite,rread,cread public wadat,trndat,rcvdat,cmddat,t3_6252 public busyfg,cs6252 csi_dat dseg saddr wadat: ds 1 ; word address storage area trndat: ds 1 ; transmission data storage area rcvdat: ds 1 ; receive data storage area cmddat: ds 1 ; command data storage area csi_flg bseg busyfg dbit ; busy state setting rwrite equ 00h ; random write mode rread equ 0c0h ; random read mode cread equ 080h ; current read mode cs6252 equ 0ff03h.2 ; 0ff03h=port3 csi_seg cseg ;************************************** ;* m pd6252 (3-wire) communication ;************************************** t3_6252: clr1 busyfg set1 cs6252 ; issue the start bit. sio0=cmddat (a) ; transfer the command. while_bit(!csiif0) ; wait for the end of transfer. endw clr1 csiif0 sio0=#0ffh ; start reception of the busy signal. while_bit(!csiif0) ; wait for the end of transfer. endw clr1 csiif0 if(sio0==#00h) ; busy check switch (cmddat) case rwrite: sio0=wadat (a) ; transfer the word address. while_bit(!csiif0) ; wait for the end of transfer. endw clr1 csiif0 sio0=trndat (a) ; start the data transfer. while_bit(!csiif0) ; wait for the end of transfer. endw clr1 csiif0 break case rread: sio0=wadat (a) ; transfer the word address. while_bit(!csiif0) ; wait for the end of transfer. endw clr1 csiif0
152 78k/0 series application note case cread: sio0=#0ffh ; start data reception. while_bit(!csiif0) ; wait for the end of transfer. endw clr1 csiif0 rcvdat=sio0 (a) ; store the receive data. ends else set1 busyfg ; set in the busy state endif clr1 cs6252 ret
153 chapter 8 serial interface application 8.2 interfacing with the osd lsi ( m pd6451a) the m pd6451a, an osd (on-screen display) lsi, displays vcr programming information or tv channels on a display by using it in conjunction with a microcontroller. to interface with the m pd6451a, the four lines of data, clk, stb, and busy are used. an example using the m PD78044F subseries is described here. figure 8-13. connection example with m pd6451a figure 8-14. m pd6451a communication format the output of the strobe signal (stb) and testing the busy signal (busy) used in handshaking for interfacing to the m pd6451a are automatically performed in serial interface channel 1 of the 78k/0 series. to match the m pd6451as communication format, the strobe signal output enable and busy signal input enable (active high) mode is selected. data (maximum of 32 bytes) to be transmitted to the buffer ram area (fac0h-fadfh) are automatically transmitted when the number of data bytes to be transmitted is set at the automatic data transmit/receive address pointer (adtp) and multiple bytes of data are consecutive. sck1 so1 stb busy do7 do6 do5 do4 do3 do2 do1 do0 clk data stb busy sck1 so1 stb busy PD78044F pd6451a rgb rgb display
154 78k/0 series application note (1) package description tr6451 : name of m pd6451a transfer subroutine dtval : area for setting the number of transmission data bytes a name use attributes bytes dtval stores the number of bytes of transmission data saddr 1 1 level, 2 bytes ? serial interface channel 1 ? serial interface channel 1 settings automatic transmit/receive operation enabled, msb first csim1=#10100011b busy input enabled (active high), strobe output enabled, single shot mode adtc=#00000110b ? interval time for data transfer adti=#00000000b ? serial clock f x /2 4 tcl3=#1000xxxxb ? set the p22 output latch to the high level. ? p21, p22, p23 set in output mode, p24 in input mode pm2=#xxx1000xb when data will be transmitted to the buffer ram (transmission from a high order address), the number of data bytes to be transmitted is set in dtval and tr6451 is called. when the data transfer ends, bit 3 (trf) of the automatic data transmit/receive control register (adtc) can be tested for verification.
155 chapter 8 serial interface application (2) use example extrn tr6451, dtval sck1 equ p2.2 : : p2=#00000100b pm2=#11110001b csim1=#10100011b ; set to the automatic transmit/receive function. tcl3=#10001000b ; sck1 = 262 khz adtc=#00000110b ; the strobe and busy signals are present. adti=#00000000b : : de=#table1 ; table reference address setting for transmission data hl=#0fac0h ; start address setting of the buffer ram b=32 ; number of transmission data bytes setting while(b>#0) ; transfer transmission data to the buffer ram. b-- [hl+b]=[de] (a) de++ endw datval=#32 ; number of transmission data bytes setting call !tr6451 while_bit(trf) ; wait for the transfer to end. endw set data in the buffer ram. set the number of transmission data bytes in dtval. call tr6451. while : waiting for the transfer to end
156 78k/0 series application note table1: db 11111111b ; power-on-reset command 1 db 01000000b ; vertical address 0 db 11000000b ; horizontal address 0 db 10000000b ; character size db 11111100b ; command 0 db 11101001b ; lc send on, blinking off, display on db 10001100b ; blinking on, character: red db 11011011b ; color setting, background color: cyan db 10010101b ; display line 5 db 10100000b ; display digit 0 db 07h ; 7 db 08h ; 8 db 1bh ; k db 6dh ; / db 00h ; 0 db 10h db 11h ; a db 20h ; p db 20h ; p db 1ch ; l db 19h ; i db 13h ; c db 11h ; a db 24h ; t db 19h ; i db 00h ; o db 1eh ; n db 10h db 1eh ; n db 00h ; o db 24h ; t db 15h ; e remark for information on the commands and data in the output table data, refer to the m pd6451a data sheet (document no. ic-2337a).
157 chapter 8 serial interface application (3) spd chart (4) program listing public tr6451,dtval csi_dat dseg saddr dtval: ds 1 ; number of data bytes setting area csi_seg cseg ;******************************* ;* m pd6451a communication ;******************************* tr6451: a=dtval ; number of data bytes setting a-- adtp=a sio1=#0ffh ; start the transfer. ret set (number-of-data-bytes-transferred ?1) in adtp. set in the state before transfer. start the transfer. tr6451
158 78k/0 series application note 8.3 sbi mode interface the 78k/0 series has the sbi mode which conforms to the nec serial bus format. the sbi mode allows one master cpu to communicate with multiple slave cpus via the two wires of clock and data. an example using the m PD78044F subseries is explained here. figure 8-15 shows a connection example and figure 8-16 shows the communication format when using the sbi mode. figure 8-15. connection example of the sbi mode sb0 sck0 PD78044F master PD78044F slave sb0 sck0 slave cpu sb sck slave cpu sb sck v dd
159 chapter 8 serial interface application figure 8-16. sbi mode communication format (a) address transmission (b) command transmission (c) data transmission and reception table 8-5. sbi mode signal list signal name output side meaning address master slave device selection command master instruction to a slave device data master/slave data processed by a slave or master clock master transmit/receive synchronization signal for serial data ack receiving side note reception response signal busy slave state where communication is not possible note during normal operation, the receiving side outputs this signal, but when an error occurs that results in time out processing, the master cpu outputs this signal. sck0 sb0 reld set cmdd set a7 a6 a5 a4 a3 a2 a1 a0 sck0 sb0 cmdd set c7 c6 c5 c4 c3 c2 c1 c0 sck0 sb0 ackd set d7 d6 d5 d4 d3 d2 d1 d0 ack
160 78k/0 series application note 8.3.1 application as a master cpu the processing in (a) to (d) is performed for the slave cpu. (a) address transmission (b) command transmission (c) data transmission (d) data reception error checks <1> and <2> are performed in the communication in (a) to (d). <1> time out processing during a master cpu transmission, when the ack signal is not returned within a constant time (here, within the time it takes for the watch timer to generate five interrupt requests), an error is judged. the master cpu outputs the ack signal and processing ends. figure 8-17. timed out ack signal <2> bus line test the master cpu tests whether the data was correctly output to the bus line by setting the transmission data in serial i/o shift register 0 (sio0) and slave address register (sva). because bus line data is received by sio0, the normal output of data is verified by testing bit 6 (coi) of serial operating mode register 0 (csim0) (set when sio0 and sva match) at the end of transfer. figure 8-18. bus line test in figure 8-18, because the values at the end of transfer do not match (sio0 = 07h, sva = 0fh), coi = 0 results and an error is generated in the bus line. sb0 inttm3 (ackd test) ack end of transfer master output (time out) 00001111 00000111 sio0 = 0fh sb0 = 07h
161 chapter 8 serial interface application (1) package description m_trans : name of master sbi transfer subroutine tr_mode: storage area of the selection of the transfer mode trndat : transmission data storage area rcvdat : receive data storage area tradr : selection of the address transmission mode trcmd : selection of command transmission mode trdat : selection of data transmission mode rcdat : selection of data reception mode errorf : error state test flag subroutine a name use attributes bytes tr_mode stores the selection of the transfer mode saddr 1 ackct time out counter trndat stores the transmission data rcvdat stores the receive data name use rcvflg reception mode setting busyfg busy state setting errorf error state setting ackwfg ack signal wait state setting 2 levels, 5 bytes ? serial interface channel 0 ? watch timer
162 78k/0 series application note ? serial interface channel 0 settings sbi mode, sb1 pin selection csim0=#10010011b ? serial clock f x /2 4 tcl3=#xxxx1000b ? set so0 latch high. relt = 1 ? set the p27 output latch to the high level. p27=1 ? 1.95-ms interval for the watch timer tmc2=#00100110b ? watch timer interrupt enabled the data required for the transfer mode is set and m_trans is called. after returning from the subroutine, by testing the error flag (errorf), the presence of a transfer error can be determined. in addition, during the receiving mode, after returning from the subroutine, the reception data is saved in rcvdat.
163 chapter 8 serial interface application (2) use example extrn m_trans,tr_mode,tradr,trcmd,trdat,rcdat extrn trndat,rcvdat extbit errorf sck0 equ p2.7 sb1 equ p2.5 : : set1 sb1 csim0=#10010111b ; operate in the sbi mode. tcl3=#10001000b ; sck0 = 262 khz tmc2=#00100110b ; set a 1.95-ms interval for the watch timer. clr1 bsye ; disable the busy signal output. set1 relt ; set the output latch. set1 sck0 clr1 sb1 clr1 csimk0 ; enable serial interface channel 0 interrupt. clr1 tmmk3 ; enable watch timer interrupt. ei ; enable master interrupt. : : tr_mode=#tradr trndat=#5ah call !m_trans if_bit(errorf) error processing endif transfer mode setting transmission data setting call m_trans. if : error occurs. error processing
164 78k/0 series application note (3) spd chart case : tr_mode m_trans of : tradr while : sb0 = low while : sck0 = low output command signal. output bus release signal. of : trcmd while : sb0 = low while : sck0 = low output command signal. of : trdat set in the transmission mode. clear rcvflg. break of : rcdat set to the transfer state. set busyfg. set transmission data in sio0 and sva. while : busy transferring (set busyfg) save sio0 data in rcvdat. if : transmission mode set in the reception mode. set rcvflg. set the output off data (ffh) of the bus line. break then then set the error state. set errorf. if : error generated in the bus line
165 chapter 8 serial interface application select register bank 0 if : transmission mode output ack signal clear busyfg, errorf then set the ack waiting state. set ackwfg intcsi0 then else release the busy state. clear busyfg release the error state. clear errorf else if : no ack signal reception select register bank 0 if : ack waiting state then release the ack waiting state. clear ackwfg release the busy state. clear busyfg inttm3 then else if : time out if : ack signal has been received. then process the time out error release the ack waiting state clear ackwfg release the busy state clear busyfg
166 78k/0 series application note (4) program listing public m_trans,tr_mode,tradr,trcmd,trdat,rcdat public trandat,rcvdat,errorf vecsi0 cseg at 0eh dw intcsi0 ; vector address setting of serial interface channel 0 vetm3 cseg at 12h dw inttm3 ; vector address setting of the watch timer sbi_dat dseg saddr trndat: ds 1 ; transmission data rcvdat: ds 1 ; reception data tr_mode: ds 1 ; transfer mode setting ackct: ds 1 ; ack time out count sbi_flg bseg rcvflg dbit ; reception mode setting busyfg dbit ; busy transferring state errorf dbit ; error display ackwfg dbit ; ack wait state sb0 equ p2.5 sck0 equ p2.7 tradr equ 1 ; address transmission mode selection trcmd equ 2 ; command transmission mode selection trdat equ 3 ; data transmission mode selection rcdat equ 4 ; data reception mode selection
167 chapter 8 serial interface application ;************************************* ;* sbi data transfer processing ;************************************* sbi_seg cseg m_trans: switch(tr_mode) case tradr: set1 pm2.5 while_bit(!sb0) ; sb0 = high? clr1 pm2.5 endw while_bit(!sck0) ; sck = high? endw set1 cmdt ; command signal output nop ; wait set1 relt ; bus release signal output a=#trcmd case trcmd: set1 pm2.5 while_bit(!sb0) ; sb0 = high? clr1 pm2.5 endw while_bit(!sck0) ; sck = high? endw set1 cmdt ; command signal output a=#trdat case trdat: clr1 rcvflg ; set in the transmission mode. a=trndat ; transmission data setting break case rcdat: set1 rcvflg ; set in the reception mode. mov a,#0ffh ; reception buffer off break ends set1 busyfg ; set in the busy transferring state. sva=a ; for use in bus line testing sio0=a ; start transfer. while_bit(busyfg) ; busy transferring endw rcvdat=sio0 (a) ; reception data storage if_bit(!rcvflg) ; reception mode if_bit(!coi) ; bus line output is no good. set1 errorf ; set in the error state. endif endif ret
168 78k/0 series application note ;************************************ ;* intcsi0 interrupt processing ;************************************ csi_seg cseg intcsi0: sel rb0 if_bit(!rcvflg) ; transmission mode if_bit(!ackd) ; no acknowledge signal received ackct=#5 ; setting of the acknowledge signal wait state set1 ackwfg else clr1 busyfg ; release the busy state. clr1 errorf ; release the error state. endif else set1 ackt ; output the acknowledge signal. clr1 busyfg ; release the busy state. clr1 errorf ; release the error state. endif reti ;************************************ ;* time out processing ;************************************ tm3_seg cseg inttm3: sel rb0 if_bit(ackwfg) ; in the acknowledge signal wait state? if_bit(ackd) ; has the acknowledge signal been received? clr1 ackwfg ; release the acknowledge signal wait state. clr1 busyfg ; release the busy state. else ackct-- if(ackct==#0) ; time out? set1 ackt ; time out error processing set1 errorf clr1 ackwfg ; release the acknowledge signal wait state clr1 busyfg ; release the busy state. endif endif endif
169 chapter 8 serial interface application 8.3.2 application as a slave cpu addresses, commands, and data are received from the master cpu and data are transmitted to the master cpu. in this example, the wakeup function is used and an address is received. a wakeup function is a function that generates an interrupt request signal only when the address transmitted by the master cpu matches the value set in the slave address register (sva) while in the sbi mode. consequently, intcsi0 is generated only in the slave cpu selected by the master cpu. the slave cpus that are not selected can be operated without generating a spurious interrupt request. when selected, a slave cpu releases the wakeup function (generates an interrupt request signal at the end of the transfer) and interfaces with the master cpu. in addition, discriminating addresses, commands, and data is done by testing bits 2 and 3 (reld and cmdd) of the serial bus interface control register (sbic). because there is no automatic return to a state where no slave cpu is selected, a program is required that returns to the unselected state by, for example, command processing between the master and slaves. (1) package description rcvdat: reception data storage area bank 0: a name use attributes bytes rcvdat stores the reception data saddr 1 name use rcvflg reception mode setting 1 level, 3 bytes ? serial interface channel 0
170 78k/0 series application note ? serial interface channel 0 settings sbi mode, sb1 pin, wakeup mode serial clock is the external clock input csim0=#10010011b ? synchronous busy signal output byse=1 ? set the so0 latch to the high level. relt=1 ? slave address sva=#slvadr ? enable serial interface channel 0 interrupt generating intcsi0 starts interrupt servicing. the following processing occurs in the interrupt servicing. ? address, command, and data discrimination ? ack signal output ? storing the receive data in rcvdat. (2) use example extrn rcvdat extbit rcvflg slvadr equ 5ah sb1 equ p2.5 : : set1 sb1 csim0=#10110100b ; select the external clock input, sb1 pin, wakeup mode set1 relt ; set the output latch to the high level. set1 bsye ; set in the busy automatic output mode. sva=#slvadr ; slave address setting sio0=#0ffh ; start serial transfer instruction clr1 sb1 clr1 csimk0 ; enable the serial interface channel 0 interrupt. ei ; enable the master interrupt.
171 chapter 8 serial interface application (3) spd chart command reception processing output the ack signal. release the wakeup mode. output the ack signal. address matching processing select register bank 0. if : address reception intcsi0 then else then if : command reception else then data reception processing output the ack signal. if : reception mode else data transmission processing save sio0 data in memory.
172 78k/0 series application note (4) program listing vecsi0 cseg at 0eh dw intcsi0 ; vector address setting of serial interface channel 0 csi_dat dseg saddr rcvdat: ds 1 ; receive data storage area csi_flg bseg rcvflg dbit ; reception mode setting csi_seg cseg ;************************************ ;* intcsi0 interrupt processing ;************************************ intcsi0: sel rb0 if_bit(reld) ; go to address reception. clr1 wup ; release the wakeup mode. set1 ackt ; output the acknowledge signal. ; user processing (address reception) ;************************************ elseif_bit(cmdd) ; go to command reception. ; user processing (command reception) set1 ackt ; output the acknowledge signal. else if_bit(rcvflg) ; user processing (data reception processing) set1 ackt ; output the acknowledge signal. else ; user processing (data transmission processing) endif ;************************************ endif rcvdat=sio0 (a) reti
173 chapter 8 serial interface application figure 8-20. communication format of the 3-wire serial i/o mode 8.4 3-wire serial i/o mode interface the function of the 3-wire serial i/o mode (serial clock, data input, data output) of serial channel 0 of the 78k/0 series is used in communication between the master and slave cpus. in this example, synchronized master-slave communication is demonstrated by adding one busy signal line as the handshake signal. the busy signal is active-low and is output by the slaves. in addition, data is 8 bits long and the msb is transmitted first. an example using the m PD78044F subseries is described. figure 8-19. connection example of the 3-wire serial i/o mode busy sck0 so0 si0 do7 do6 do5 do4 do3 do2 do1 do0 di7 di6 di5 di4 di3 di2 di1 di0 sck0 so0 si0 busy sck0 si0 so0 busy master slave
174 78k/0 series application note 8.4.1 application as a master cpu the serial clock is set to f x /2 4 . communication with the slave cpu is performed synchronized to this serial clock. after setting the transmission data, the master cpu begins the transfer. however, when the slave cpu is in the busy state (low busy signal), there is no transfer and the busy flag (busyfg) is set. (1) package description trans : name of the master 3-wire transfer subroutine tdata : transmission data storage area rdata : receive data storage area busy : busy signal input port trend : end of transfer test flag busyfg : busy state test flag interrupt bank 0 a subroutine a name use attributes bytes tdata stores the transmission data saddr 1 rdata stores the receive data name use trend end of transfer state setting busyfg busy state setting 2 levels, 5 bytes ? serial interface channel 0 ? p33
175 chapter 8 serial interface application ? serial interface channel 0 settings 3-wire serial i/o mode, msb first csim0=#10000011b ? serial clock f x /2 4 tcl3=#xxxx1000b ? set the p27 output latch to the high level. p27=1 ? p33 input mode ? enable the serial interface channel 0 interrupt. the transmission data is set in tdata and trans is called. after returning from the subroutine, the busy flag (busyfg) is tested. when the busy flag is set, the transfer must be repeated because no transfer was performed. in addition, when the busy flag is cleared, receive data is saved in rdata because the transfer has ended.
176 78k/0 series application note (2) use example extrn tdata,rdata,trans extbit trend,busyfg,busy sck0 equ p2.7 : : csim0=#10000011b ; set to 3-wire serial i/o mode and msb first. tcl3=#10001000b ; set to sck0 = 262 khz. set1 sck0 set1 pm3.3 ; bit 3 of port 3 set in input mode clr1 csimk0 ; enable the serial interface channel 0 interrupt. ei : : tdata=a ; transmission data setting repeat clr1 busyfg ; busy test call !trans until_bit(!busyfg) while_bit(!trend) ; end of transfer endw a=rdata ; read in the received data. (3) spd chart set transmission data. until : busyfg is cleared clear busyfg. call trans. while : trend is cleared. read in the receive data then if : transfer is possible set transmission data in sio0. set in busy state. set busyfg. else trans select register bank 0. save sio0 data in memory. set in the end of transfer state. set trend. intcsi0
177 chapter 8 serial interface application (4) program listing public trans,rdata,tdata,busy,trend,busyfg vecsi0 cseg at 0eh dw intcsi0 ; vector address setting of serial interface channel 0 busy equ 0ff03h.3 ; 0ff03h = port 3 csi_dat dseg saddr rdata: ds 1 ; receive data storage area tdata: ds 1 ; transmission data storage area csi_flg bseg trend dbit ; end of transfer state setting busyfg dbit ; busy state setting csi_seg cseg ;************************************ ;* intcsi0 interrupt servicing ;************************************ intcsi0: sel rb0 rdata=sio0 (a) ; save receive data. set1 trend ; set in the end of transfer state. reti ;************************************ ;* 3-wire (master) ;************************************ trans: if_bit(busy) ; transfer possible state sio0=tdata (a) ; set the transmission data. else set1 busyfg ; set in busy state. endif ret
178 78k/0 series application note 8.4.2 application as a slave cpu synchronous transmission/reception of 8-bit data is performed while synchronized to the serial clock from the master cpu. the busy signal from the slave cpu is output at a low level (busy state) while the transmission data is being prepared. the output timing of this busy signal releases the busy signal (high level) by setting the transmission data (call !trans). a busy signal (low level) is output as a result of interrupt servicing for intcsi0 at the end of the transfer. consequently, the busy state begins at the end of the transfer and lasts until the data is set. figure 8-21. busy signal output (1) package description trans: name of the slave 3-wire transfer subroutine tdata : transmission data storage area rdata: receive data storage area busy : busy signal output port trend: end of transfer test flag interrupt bank 0 a subroutine a busy intcsi0 transmission wait during transmission preparing the transmission data transmission data setting transmission data setting
179 chapter 8 serial interface application name use attributes bytes tdata store the transmission data. saddr 1 rdata store the receive data. name use trend end of transfer state setting 2 levels, 5 bytes ? serial interface channel 0 ? p33 ? serial interface channel 0 settings 3-wire serial i/o mode, msb first, external clock input csim0=#10000000b ? p33 set in output mode p33=0 ? busy state setting ? enable the serial interface channel 0 interrupt. the transmission data is set in tdata and trans is called. because the busy signal is released in trans processing, the state to wait for communication with the master cpu is entered. after communication ends, interrupt service is started by generating intcsi0. the end of the transfer can be verified by testing trend. after trend is set, the received data is saved in rdata.
180 78k/0 series application note (2) use example extrn tdata,rdata,trans extbit trend,busy : : csim0=#10000000b ; set to the 3-wire serial i/o mode and msb first. clr1 busy ; busy state clr1 pm3.3 ; bit 3 of port 3 set in output mode clr1 csimk0 ; enable the serial interface channel 0 interrupt. ei : : tdata=a ; transmission data setting call !trans while_bit(!trend) ; end of transfer endw a=rdata ; read in the receive data (3) spd chart set transmission data. call trans. while : trend is clear read in the received data select register bank 0. output the busy signal. save sio0 data in memory. set in the end of transfer state. intcsi0 set transmission data in sio0. release the busy signal. trans
181 chapter 8 serial interface application (4) program listing public rdata,tdata,busy,trend,busyfg public trans vecsi0 cseg at 0eh dw intcsi0 ; vector address setting of serial interface channel 0 csi_dat dseg saddr rdata: ds 1 ; receive data storage area tdata: ds 1 ; transmission data storage area csi_flg bseg trend dbit ; end of transfer state setting busyfg dbit ; busy state setting busy equ 0ff03h.3 ; 0ff03h=port3 csi_seg cseg ;************************************* ;* intcsi0 interrupt servicing ;************************************* intcsi0: sel rb0 clr1 busy ; set in the busy state. rdata=sio0 (a) ; save the receive data. set1 trend ; set in the end of transfer state. reti ;************************************* ;* 3-wire (slave) ;************************************* trans: sio0=tdata (a) ; transmission data setting set1 busy ; release the busy state. ret
182 78k/0 series application note 8.5 half-duplex asynchronous communication the clocked serial interface channel 0 is used to perform half-duplex asynchronous communication. two application examples are presented using the 3-wire mode and the sbi mode. the communication protocol is as follows. transmission speed : 9600 bps start bit : 1 bit character length : 8 bits (lsb first) parity bit : 1 bit (even/odd parity can be selected) stop bit : 2 bits because the transmission speed is set to 9600 bps, 8-bit timer/event counter 2 is used to generate the serial clock. 8.5.1 half-duplex asynchronous communication of the 3-wire mode figure 8-22 illustrates the system structure. serial input and output is performed via the si0 and so0 pins, respectively. bits 0 and 1 of port 3 are used as i/o for the busy signal. when the busy signal is l, serial communication is possible. figure 8-22. system structure (3-wire mode) intp1 si0 so0 p30 p31 so0 si0 intp1 p31 p30 PD78044F PD78044F serial i/o busy signal i/o
183 chapter 8 serial interface application (1) transmission in the 3-wire mode data transmission processing is explained below. <1> start bit -> transmission time wait based on the output latch operation of the serial interface and 8-bit timer/event counter 2 caution to prevent a timing delay in data reception due to the loss of the start bit, assign high priority to the intp1 interrupt request. <2> data -> transmission by the serial buffer <3> parity bit -> the output latch of the serial interface is manipulated in the interrupt servicing of 8-bit timer/event counter 2 and the parity bit is output. caution to prevent a delay in the transmission timing, assign high priority to interrupt requests from 8-bit timer/event counter 2. <4> stop bit -> the output latch of the serial interface in the interrupt servicing in 8-bit timer/event counter 2 is set and the stop bit is output. caution to prevent a delay in the transmission timing, assign high priority to interrupt requests from 8-bit timer/event counter 2. figure 8-23. 3-wire mode transmission format d1 d0 d2 d3 d4 d5 d6 d7 stop bits start operation of timer 2 serial busy input pin p30 serial data output so0 serial clock timer 2 interrupt request processing output by the receiving side start bit parity bit enable intcsi0 and timer 2 interrupts. disable timer 2 interrupt. write data in sio0
184 78k/0 series application note (2) reception in the 3-wire mode the following example illustrates data reception processing. <1> start bit -> reception is started by a port test and the detection of a falling edge at the intp1 pin. caution to prevent a timing delay in data reception due to the loss of the start bit, assign high priority to the intp1 interrupt request. <2> data -> reception by the serial buffer <3> parity bit -> the port is tested in the interrupt servicing of 8-bit timer/event counter 2 and the parity bit is output. caution to prevent a delay in reception timing, assign high priority to interrupt requests from 8-bit timer/event counter 2. <4> stop bit -> the port is tested in the interrupt servicing for 8-bit timer/event counter 2 and the stop bit is output. caution to prevent a delay in reception timing, assign high priority to interrupt requests from 8-bit timer/event counter 2. when a parity error or an overrun error is generated, the flag is set. figure 8-24. 3-wire mode reception format d1 d0 d2 d3 d4 d5 d6 d7 enable intcsi0 and timer 2 interrupts. timer 2 interrupt disable timer 2 interrupt. stop bits start timer 2 by intp1 interrupt serial busy output pin p31 serial data input si0 serial clock timer 2 interrupt request processing inverted by the serial interrupt. start bit parity bit write ffh in sio0 and disable intp1.
185 chapter 8 serial interface application (3) package description ? subroutine names s_soshin : name of transmission subroutine s_jushin : name of reception subroutine ? input parameters sodata : stores transmission data f_parity : indicates an even or odd parity selection state f_tushin : indicates a receiving or transmitting state ? output parameters judata : stores the receive data f_data : this is set after reception ends. f_errp : indicates a parity error f_erre : indicates an end bit error ? i/o parameter f_padata : stores the communication parity bit bank 0 a bank 1 a bank 2 a name use attributes bytes sodata transmission data storage area saddr 1 judata receive data storage area saddr 1 c_work state storage counter saddr 1 i work counter for loop operation saddr 1 j work counter for loop operation saddr 1
186 78k/0 series application note name use f_parity parity selection flag set when odd parity is selected. f_padata parity bit storage flag stores the parity. f_tushin communication flag set during communication. f_errp parity error flag set when a parity error occurs. f_erre end bit error flag set when an end bit error occurs. f_data end of reception flag set at the end of reception. f_work work flag for work 1 level, 3 bytes ? serial interface channel 0 (3-wire mode) ? 8-bit timer/event counter 2 ? external interrupt edge detection (intp1 pin) ? set in the s_soshin and s_jushin subroutines. ? port 2: bit 5 input port; bit 6 output port settings pm2=#x01xxxxxb ? port 3: bit 0 input port; bit 1 output port settings pm3=#xxxxxx01b ? serial interface channel 0 settings 3-wire mode, serial clock = 8-bit timer/event counter 2 selection csim0=#10000110b ? 8-bit timer/event counter 2 setting 9600-bps baud rate setting cr20=#54 8-bit timer register x 2-channel mode tcl1=#01100000b 8-bit timer/event counter 2 operation disabled toc1=#00000000b tmc1=#00000000b ? intp1 setting intp1 falling edge intm0=#00000000b ? high priority 8-bit timer/event counter 2 interrupt clr1 tmpr2 ? high priority intp1 interrupt clr1 ppr1 ? serial interface interrupt enabled clr1 csimk0
187 chapter 8 serial interface application ? set in the following order when starting data transmission or reception. ? starting data transmission <1> store the transmission data in the sodata area. <2> set the transmission flag. <3> call the s_soshin subroutine. ? starting data reception <1> clear the communication flag (f_tushin). (set to 0.) <2> invert the busy signal. <3> call the s_jushin subroutine. ? when interrupt requests other than those in the 78k/0 series package are used, to enable high priority interrupts, set the isp flag to 0 at the beginning of interrupt processing and enable interrupts.
188 78k/0 series application note (4) use example this example illustrates selecting an even or odd parity bit and selecting transmission or reception by using key input. extrn sodata extrn judata,s_soshin,s_jushin extbit f_parity,f_data,f_padata,f_tushin extbit f_erre,f_errp ; busy_o equ p3.1 busy_i equ p3.0 parikey equ 22 ; decoded parity key value jyushin equ 21 ; decoded reception key value tushin equ 20 ; decoded transmission key value ;*************************************** ; initialize ;*************************************** veres cseg at 00h dw res_sta m3 cseg ; res_sta: ; mov p2,#0bfh ; p2.5=h,p2.6=l mov p3,#0ffh ; mov pm2,#00100000b ; p2.5 = input port, p2.6 = output port mov pm3,#00000001b ; p3.0 = input port, p3.1 = output port ;***8-bit timer register settings*** cr20=#54 ; tcl1=#01100000b ; 1.05-mhz count clock toc1=#00000000b ; tmc1=#00000000b ; 8-bit timer register selection, timer 2 operation disabled ;***serial interface 0 settings*** csim0=#10000110b ; 3-wire mode, serial clock selection, 8-bit timer 2 set1 relt ; ;***intp1 settings*** intm0=#00000000b ; intp1 falling edge clr1 tmpr2 ; high priority timer 2 interrupt clr1 ppr1 ; high priority intp1 interrupt clr1 pif1 ; clear the intp1 request flag. clr1 tmif2 ; clear the timer 2 request flag. clr1 csiif0 ; clear the serial interface request flag. clr1 csimk0 ; enable the serial interface interrupt. while(forever) ; . ; . ;
189 chapter 8 serial interface application if_bit(f_keyon) ; is the key on flag 1? switch(m_keyon) ; case parikey: ; the pressed key was the parity key. set1 cy ; invert the even/odd parity decision cy ^=f_parity ; f_parity=cy ; break ; case tushin: ; the pressed key was the communication key. set1 f_tushin ; set the communication flag (during transmission). clr1 f_soend ; break ; case jyushin: ; the pressed key was the reception key. clr1 f_tushin ; clear the communication flag (during reception) cy=busy_0 ; inverted busy signal data is output. not1 cy ; busy_0=cy ; if_bit(cy) ; set1 pmk1 ; intp1 interrupt is disabled. else ; clr1 f_errp ; clr1 f_erre ; call !s_jushin ; endif ; break ; ends ; endif ; . . . if_bit(!f_soend) ; if_bit(f_tushin) ; is the communication flag set? cy=busy_i ; is the busy signal inactive? if_bit(!cy) ; sodata=#0 ; set1 f_soend ; sodata=work ; transmission data storage area <- transmission data call !s_soshin ; endif ; endif ; endif
190 78k/0 series application note (5) spd chart [reception subroutine] [transmission subroutine] clear intp1 request flag. enable intp1 interrupt. s_jushin then if (odd parity is selected) set the parity data flag. s_soshin for (i = #0 ; i < #8 ; i+ +) cy <- least significant bit of the transmission data the exclusive-or is taken of cy and the parity data flag. transfer the result to the parity data flag. the timer output flip-flop of 8-bit timer/event counter 2 is reset and the inversion operation is enabled. clear request flag of 8-bit timer/event counter 2. disable interrupts. enable 8-bit timer/event counter 2 operation. transmit the start bit. wait the time it takes to transmit the start bit. sio0 <- transmission data enable interrupts.
191 chapter 8 serial interface application [parity end bit communication processing (8-bit timer/event counter 2 interrupt)] switch to bank 1. if (transmitting data) taima2 then switch (what data is being transmitted?) [case : 1] [case : 2] [case : 3] parity data transmission first end bit transmission second end bit transmission disable 8-bit timer/event counter 2 interrupt. disable operation of 8-bit timer/event counter 2. switch (what data is being received?) [case : 1] [case : 2] [case : 3] parity data read if (is first end bit error present?) then set end bit error flag. then set end bit error flag. if (is second end bit error present?) disable 8-bit timer/event counter 2 interrupt. disable operation of 8-bit timer/event counter 2. if (does parity data match?) then if (is end bit present?) then set end of reception flag. else set parity error flag.
192 78k/0 series application note [data transmission/reception completion processing] [startup processing for data reception (intp1 interrupt processing)] intp1 switch to bank 1. clear the 8-bit timer/event counter 2 request flag. clear the 8-bit timer 2 counter. enable the operation of 8-bit timer/event counter 2. wait the time to read the start bit. if (is the intp1 pin asserted?) then disable intp1 interrupt. read preparation for receive data intsi0 switch to bank 2. clear 8-bit timer/event counter 2 request flag. enable 8-bit timer/event counter 2 interrupt. output 'h' to the busy0 signal. if (receiving) then read in receive data.
193 chapter 8 serial interface application (6) program listing public f_padata,f_parity public f_data,f_tushin public judata,sodata,s_jushin,s_soshin public f_errp,f_erre ; veintp1 cseg at 08h dw intp ; intp1 vector address setting veintsi0 cseg at 0eh dw intsi0 ; vector address setting of serial interface channel 0 vetim2 cseg at 18h dw taima2 ; vector address setting of 8-bit timer 2 ; si0 equ p2.5 busy_0 equ p3.1 busy_1 equ p3.0 ; moram dseg saddr sodata: ds 1 ; transmission data storage area c_work: ds 1 ; work counter judata: ds 1 ; received data storage area i: ds 1 ; work counter k: ds 1 ; work counter ; moflg bseg f_parity dbit ; parity selection flag f_errp dbit ; parity error flag f_erre dbit ; end bit error flag f_data dbit ; end of reception flag f_padata dbit ; parity data flag f_work dbit ; work flag f_tushin dbit ; communication flag ;********************************** ; reception routine ;********************************** jushin cseg ; s_jushin: ; clr1 pif1 ; clear intp1 request flag. clr1 pmk1 ; enable the intp1 interrupt. ret ;
194 78k/0 series application note ;************************************ ; transmission routine ;************************************ soshin cseg s_soshin: ; clr1 f_padata ; clear parity data. if_bit(f_parity) ; is odd parity selected? set1 f_padata ; set parity data. endif ; a=sodata ; for(i=#0;i<#8;i++) ; determine parity data. rorc a,1 ; cy ^=f_padata ; f_padata = cy ; next ; toc1=#01100000b (a) ; clr1 tmif2 ; clear timer 2 request flag. di ; set1 tce2 ; enable 8-bit timer operation. set1 cmdt ; transmit the start bit. while_bit(!tmif2) ; wait for the start bit to be transmitted. endw ; clr1 tmif2 ; sio0=sodata (a) ; start data transmission. ei ; ret ; ;************************************ ; timer 2 interrupt servicing ;************************************ tim2 cseg ; taima2: ; sel rb1 ; set to bank 1. if_bit(f_tushin) ; is the communication flag set? if(c_work <= #4) ; work counter contents switch(c_work) ; 0: parity data transmission case 0: ; if_bit(f_padata) ; set1 relt ; else ; set1 cmdt ; endif ; break ; case 2: ; 2: end bit transmission set1 relt ; transmit h. break ; case 4: ; 4: end bit transmission set1 relt ; transmit h. set1 tmmk2 ; disable timer 2 interrupt. clr1 tce2 ; disable 8-bit timer operation. c_work=#0 ; break ; ends ; c_work++ ; else ; c_work=#0 ; endif
195 chapter 8 serial interface application else ; if(c_work <= #6) ; receiving? switch(c_work) ; work counter contents case 1: ; 1: read in parity data cy=si0 ; f_padata=cy ; break ; case 3: ; 3: check the end bit if_bit(!si0) ; if an error is present, set the end bit error flag. set1 f_erre ; endif ; break ; case 5: ; 5: check the end bit if_bit(!si0) ; if an error is present, set the end bit error flag. set1 f_erre ; endif ; c_work=#0 ; set1 tmmk2 ; disable timer 2 interrupt. clr1 tce2 ; disable 8-bit timer operation. clr1 f_work ; if_bit(f_parity) ; set1 f_work ; endif ; a=judata ; for(i=#0;i<#8;i++) ; store in the receive data. rorc a,1 ; cy ^= f_work ; f_work = cy ; next ; clr1 f_errp ; clr1 f_data ; f_work ^= f_padata (cy) ; if_bit(!f_work) ; check parity data. if_bit(!f_erre) ; check end bit data. set1 f_data ; endif ; else ; if parity data matches, set f_data. set1 f_errp ; if the parity data does not match, set the parity error flag. endif ; break ; ends ; c_work++ ; else ; c_work=#0 ; endif ; endif ; reti ;
196 78k/0 series application note ;********************************************* ; intsi0 interrupt servicing (reception) ;********************************************* s_si0 cseg ; intsi0: ; sel rb2 ; set to bank 2. clr1 tmif2 ; clear timer 2 request flag. clr1 tmmk2 ; enable timer 2 interrupt. set1 busy_0 ; output high busy signal. if_bit(!f_tushin) ; judata=sio0 (a) ; endif ; c_work=#0 ; clear the work counter to zero. reti ; ;********************************************* ; intp1 interrupt servicing (reception) ;********************************************* s_p1 cseg ; intp1: ; sel rb1 ; clr1 tmif2 ; clear timer 2 request flag. clr1 tce2 ; clear timer 2 counter. set1 tce2 ; enable timer operation. while_bit(!tmif2) ; endw ; clr1 tmif2 ; if_bit(!si0) ; intp1 chattering processing toc1=#10100000b ; set1 pmk1 ; disable intp1 interrupt. sio0=#0ffh ; endif ; reti ; end
197 chapter 8 serial interface application 8.5.2 half-duplex asynchronous communication in the sbi mode figure 8-25 shows the system structure. serial input and output are performed via pin sb0. bits 0 and 1 of port 3 are used for input and output of the busy signal. when the busy signal is low, serial communication is possible. cautions concerning the use of the sbi mode are given below. <1> set bit 5 of port 2 (sb0) in the output mode when reset starts. however, when the sb0 port is tested, set sb0 in the input mode. at the end of port testing, set in the output mode again. <2> after the last stop bit is transmitted and detected in serial communication, enable serial operation again after it has been disabled. essentially, the end of sbi communication is determined by checking the ready signal after detecting the acknowledge signal. however, because the acknowledge signal is used in transmit- ting and receiving the parity bit, when a 1 parity bit is transmitted and received, the condition for the end of sbi communication does not hold. when this is not considered to be the end of serial communication, sometimes the next communication does not operate normally. figure 8-25. system structure (sbi mode) sb0 intp1 p30 p31 sb0 intp1 p31 p30 busy signal i/o PD78044F PD78044F serial i/o
198 78k/0 series application note (1) transmission in the sbi mode data transmission processing is shown below. <1> start bit -> transmission time wait based on the output latch operation of the serial interface and 8-bit timer/event counter 2 caution to prevent a timing delay in data reception due to the loss of the start bit, assign high priority to the intp1 interrupt request. <2> data and parity bits -> 9-bit transmission by the serial buffer and the acknowledge signal <3> stop bit -> the output latch of the serial interface is set in the interrupt servicing of 8-bit timer/event counter 2 and the stop bit is output. cautions 1. to prevent delays in the transmission timing, assign high priority to an interrupt request from 8-bit timer/event counter 2. 2. if the second stop bit has been transmitted, enable operation again after serial operation for verifying the end of transmission is disabled once. figure 8-26. sbi mode transmission format note after serial operation is disabled once, set again to enable. d1 d0 d2 d3 d4 d5 d6 d7 stop bit start timer 2 operation. serial busy input pin p30 serial data output sb0 serial clock timer 2 interrupt request processing output by the receiving side start bit parity bit enable the intcsi0 and timer 2 interrupts. disable the timer 2 interrupt. note write the parity bit to acke. write to sio0.
199 chapter 8 serial interface application (2) reception in the sbi mode data reception processing is shown below. <1> start bit -> start reception by detecting a falling edge at pin intp1 and testing the port cautions 1. when testing the port, set in the following order. <1> set bit 5 (si0) of port 2 to an input port. <2> test the port and write to sio0. <3> reset bit 5 of port 2 in the output mode. 2. to prevent delayed timing in data reception due to the loss of the start bit, assign high priority to the intp1 interrupt request. <2> data and parity bits -> reception by the serial buffer and acknowledge detection <3> stop bit -> test the port in interrupt servicing for 8-bit timer/event counter 2 and output the parity bit. cautions 1. to prevent delays in the transmission timing, assign high priority to an interrupt request from 8-bit timer/event counter 2. 2. if the second stop bit has been transmitted, enable operation again after serial operation for verifying the end of transmission is disabled once. when a parity or an overrun error occurs, set the flag. figure 8-27. sbi mode reception format serial busy output pin p31 d1 d0 d2 d3 d4 d5 d6 d7 stop bits start intp1 interrupt timer 2 serial data input sb0 serial clock timer 2 interrupt request processing invert at the serial interrupt. start bit parity bit enable the intcsi0 and timer 2 interrupts. write ffh to sio0 and disable intp1. timer 2 interrupt disable timer 2 interrupt.
200 78k/0 series application note (3) package description ? subroutine names s_soshin : name of transmission subroutine s_jushin : name of reception subroutine ? input parameters sodata : stores transmission data f_parity : indicates even and odd parity selection state f_tushin : indicates the busy receiving or transmitting state ? output parameters judata : stores receive data f_data : if reception is over, this is set. f_errp : indicates a parity error f_erre : indicates an end bit error ? i/o parameter f_padata : stores the parity bit for communication bank 0 a bank 1 a bank 2 a name use attributes bytes sodata transmission data storage area saddr 1 judata receive data storage area saddr 1 c_work state storage counter saddr 1 i work counter for loop operation saddr 1 j work counter for loop operation saddr 1
201 chapter 8 serial interface application name use f_parity parity selection flag set when odd parity is selected. f_padata parity bit storage flag stores the parity. f_tushin communication flag set during communication. f_errp parity error flag set when a parity error occurs. f_erre end bit error flag set when an end bit error occurs. f_data end of reception flag set at the end of reception. f_work work flag for work 1 level, 3 bytes ? serial interface channel 0 (sbi mode) ? 8-bit timer/event counter 2 ? external interrupt edge detection (intp1 pin) ? after a reset start at the pin (p25) for i/o data, set the following before the serial transmission of the first byte. <1> set the output latch of p25 to 1. <2> set bit 0 (relt) of the serial bus control register (sbic) to 1. <3> this time, set the output latch of the p25 set to 1 to 0. ? set in the s_soshin and s_jushin subroutines. ? port 2: bit 5 input port, bit 6 output port settings pm2=#x01xxxxxb ? port 3: bit 0 input port, bit 1 output port settings pm3=#xxxxxx01b ? serial interface channel 0 setting sbi mode, serial clock = 8-bit timer 2 selection csim0=#10010110b ? 8-bit timer/event counter 2 settings 9600-bps baud rate setting cr20=#54 8-bit timer register x 2-channel mode tcl1=#01100000b 8-bit timer/event counter 2 operation disabled toc1=#00000000b tmc1=#00000000b ? intp1 setting intp1 falling edge intm0=#00000000b ? high-priority 8-bit timer/event counter 2 interrupt clr1 tmpr2 ? high-priority intp1 interrupt clr1 ppr1 ? enable serial interface interrupt clr1 csimk0
202 78k/0 series application note ? set the following order when starting data transmission and reception. ? starting data transmission <1> store transmission data in the sodata area. <2> set transmission flag. <3> call the s_soshin subroutine. ? starting data reception <1> clear the communication flag (f_tushin). (set to 0.) <2> invert the busy signal. <3> call the s_jushin subroutine. ? when interrupt requests other than those in the 78k/0 series package are used, to enable high priority interrupts, set the isp flag to 0 at the beginning of interrupt processing and enable interrupts.
203 chapter 8 serial interface application (4) use example this example illustrates selecting an even or odd parity bit and selecting transmission or reception by using key input. extrn sodata extrn judata,s_soshin,s_jushin extbit f_padata,f_parity,f_data,f_tushin extbit f_errp,f_erre ; tushin equ 20 jyushin equ 21 parikey equ 22 busy_o equ p3.1 busy_i equ p3.0 sb0 equ p2.5 ;************************************** ; initialize ;************************************** m3s cseg ; res_sta: ; mov p2,#9fh ; p2.5=l, p2.6=l mov p3,#0ffh ; mov pm2,#00000000b ; p2.5 = output mode mov pm3,#00000001b ; p3.0 = input port, p3.1 = output port ;***8-bit timer register setting*** cr20=#54 ; tcl1=#01100000b ; 1.05-mhz count clock toc1=#00000000b ; tmc1=#00000000b ; 8-bit timer register selection and timer 2 operation disable ;***serial interface 0 settings*** set1 sb0 ; csim0=#10000110b ; sbi mode, serial clock selection, 8-bit timer 2 set1 relt ; clr1 sb0 ; ;***intp1 settings*** clr1 tmpr2 ; high priority timer 2 interrupt clr1 ppr1 ; high priority intp1 interrupt intm0=#00000000b ; intp1 falling edge clr1 pif1 ; clear the intp1 request flag. clr1 tmif2 ; clear the timer 2 request flag. clr1 csiif0 ; clear the serial interface request flag. clr1 ksif ; clear the interrupt request flag. clr1 csimk0 ; enable serial interface interrupt. clr1 ksmk ; enable intks interrupt.
204 78k/0 series application note while(forever) ; . ; . ; if_bit(f_keyon) ; is the key on flag 1? switch(m_keyon) ; case parikey: ; the pressed key was the parity key. set1 cy ; invert odd or even parity decision cy ^= f_parity ; f_parity=cy ; break ; case tushin: ; the pressed key was the communication key. set1 f_tushin ; set the communication flag (while transmitting). clr1 f_soend ; break ; case jyushin: ; the pressed key was the reception key. clr1 f_tushin ; clear the communication flag (while receiving). cy=busy_0 ; output the inverted busy signal data. not1 cy ; busy_0=cy ; it_bit(cy) ; set1 pmk1 ; disable intp1 interrupt. else ; clr1 f_errp ; clr1 f_erre ; call !s_jushin ; endif ; break ; ends ; endif . . if_bit(!f_soend) ; is the communication flag set? if_bit(f_tushin) ; is the busy signal inactive? cy=busy_i ; if_bit(!cy) ; set1 f_soend ; sodata=#0 ; sodata=work (a) ; transmission data storage area <- transmission data call !s_soshin ; call the transmission routine. endif ; endif ; endif ;
205 chapter 8 serial interface application (5) spd chart [reception subroutine] [transmission subroutine] clear intp1 request flag. enable intp1 interrupt. s_jushin then set parity data flag. s_soshin for (i = #0 ; i < #8 ; i++) cy <- least significant bit of the transmission data the exclusive-or is taken of cy and the parity data flag. transfer the result to the parity data flag. the timer output flip-flop of 8-bit timer/event counter 2 is reset and the inverse operation is enabled. clear request flag of 8-bit timer 2. disable interrupts. enable 8-bit timer 2 operation. transmit start bit. wait the time the start bit is transmitted. acke <- parity bit data sio0 <- transmission data enable interrupts. reverse the direction of the transmission data. if (odd parity is selected)
206 78k/0 series application note [stop bit transmission/reception processing (8-bit timer/event counter 2 interrupt servicing)] switch to bank 1. if (data is being transmitted) taima2 then switch (what data is being transmitted?) [case : 1] [case : 2] first end bit transmission second end bit transmission disable 8-bit timer counter 2 interrupt. disable operation of 8-bit timer 2. switch (what data is being received?) [case : 1] [case : 2] if (is the first end bit error present?) then set end bit error flag. then set end bit error flag. if (is the second end bit error present?) disable 8-bit timer counter 2 interrupt. disable operation of 8-bit timer 2. if (does the parity data match?) then set end of reception flag. else set parity error flag.
207 chapter 8 serial interface application [data transmission/reception completion processing (intsi0 interrupt servicing)] [starting processing for data reception (intp1 interrupt servicing)] switch to bank 2. clear 8-bit timer 2 request flag. enable 8-bit timer 2 interrupt. output the high level to the busy0 signal. intsi0 if (receiving) then read in received data. reverse the received data that was read in. read in parity data. switch to bank 1. clear 8-bit timer 2 counter. enable operation of 8-bit timer 2. wait the time for the start bit to be read in. intp1 if (is the intp1 pin asserted?) then clear the 8-bit timer 2 request flag. disable intp1 interrupt. received data read preparation
208 78k/0 series application note (6) program listing public judata public sodata,f_parity,s_soshin public f_data,s_jushin,f_padata,f_tushin public f_erre,f_errp ; veintp1 cseg at 08h dw intp1 veintsi0 cseg at 0eh dw intsi0 vetim2 cseg at 18h dw taima2 ; sb0 equ p2.5 busy_o equ p3.1 busy_i equ p3.0 port25 equ pm2.5 ; mosram dseg saddr sodata: ds 1 ; transmission data storage area c_work: ds 1 ; work counter judata: ds 1 ; receive data storage area i: ds 1 ; work counter k: ds 1 ; work counter ; mosflg bseg f_errp dbit ; parity error flag f_erre dbit ; end bit error flag f_data dbit ; end of reception flag f_padata dbit ; parity data flag f_parity dbit ; parity selection flag f_work dbit ; flag work area f_tushin dbit ; communication flag ; ;********************************* ; reception routine ;********************************* jushin cseg ; s_jushin: ; clr1 pif1 ; clear the request flag. clr1 pmk1 ; enable intp1 interrupt. ret ;
209 chapter 8 serial interface application ; ;************************************** ; transmission routine ;************************************** soshin cseg s_soshin: ; a=sodata ; reverse the direction of the transmission data. sodata=#0 ; if_bit(a.7) ; set1 sodata.0 ; endif ; if_bit(a.6) ; set1 sodata.1 ; endif ; if_bit(a.5) ; set1 sodata.2 ; endif ; if_bit(a.4) ; set1 sodata.3 ; endif ; if_bit(a.3) ; set1 sodata.4 ; endif ; if_bit(a.2) ; set1 sodata.5 ; endif ; if_bit(a.1) ; set1 sodata.6 ; endif ; if_bit(a.0) ; set1 sodata.7 ; endif ; clr1 f_padata ; clear the parity data flag. if_bit(f_parity) ; is odd parity currently selected? set1 f_padata ; set the parity data. endif ; a=sodata ; for(k=#0;k<#8;k++) ; parity data setting. rorc a,1 ; cy ^= f_padata ; f_padata = cy ; next ; toc1=#01100000b (a) ; clr tmif2 ; clear the timer 2 request flag. di ; set1 tce2 ; enable 8-bit timer operation. set1 cmdt ; start bit transmission. while_bit(!tmif2) ; wait the time for the start bit to be transmitted. endw ; clr1 tmif2 ; set1 acke ; clear acknowledge. if_bit(f_padata) ; clear acknowledge when parity data is 1. clr1 acke ; endif ; sio0=sodata (a) ; start data transmission ei ; ret ;
210 78k/0 series application note ; ;********************************** ; timer 2 interrupt servicing ;********************************** tim2 cseg ; taima2: ; sel rb1 ; set to bank 1. if_bit(f_tushin) ; busy communicating? if(c_work < #3) ; work mode contents switch(c_work) ; 0: end bit transmission case 0: ; set1 relt ; break ; case 2: ; 2: end bit transmission set1 relt ; disable 8-bit timer 2 interrupt. set1 tmmk2 ; clr1 tce2 ; disable 8-bit timer 2 operation. set1 sb0 ; set bit 5 of port 2 to an input port. clr1 csie0 ; disable serial operation. set1 csie0 ; enable serial operation. set1 relt ; clr1 sb0 ; set bit 5 of port 2 to an output mode. c_work=#0 ; break ; ends ; c_work++ ; else ; c_work=#0 ; endif ;
211 chapter 8 serial interface application else ; if(c_work < #4) ; busy receiving? set1 port25 ; set bit 5 of port 2 to an input port. switch(c_work) ; work mode contents case 1: ; 1: if the end bit is high, set the end bit error flag. if_bit(!sb0) ; set1 f_erre ; endif ; break ; case 3: ; 3: if the end bit is high, set the end bit error flag. if_bit(!sb0) ; set1 f_erre ; endif ; set1 sb0 ; bit 5 of port 2 = high clr1 csie0 ; disable serial operation. set1 csie0 ; enable serial operation. set1 relt ; clr1 sb0 ; bit 5 of port 2 = low c_work=#0 ; set1 tmmk2 ; disable 8-bit timer 2 interrupt. clr1 tce2 ; disable 8-bit timer operation. clr1 f_work ; if_bit(f_parity) ; set1 f_work ; endif ; a=judata ; for(i=#0;i<#8;i++) ; store in the receive data. rorc a,1 ; cy ^= f_work ; f_work = cy ; next ; clr1 f_errp ; clr1 f_data ; f_work ^= f_padata (cy) ; if_bit(!f_work) ; check parity data. if_bit(!f_erre) ; set1 f_data ; if a normal reception, set the f_data flag. endif ; else ; set1 f_errp ; if a parity error occurs, set the f_errp flag. endif ; clr1 f_work ; break ; ends ; clr1 port25 ; set bit 5 of port 2 to an output port. c_work++ ; else ; c_work=#0 ; endif ; endif ; reti
212 78k/0 series application note ; ;********************************************* ; intsi0 interrupt servicing (reception) ;********************************************* s_si0 cseg ; intsi0: ; sel rb2 ; clr tmif2 ; clear timer 2 request flag. clr1 tmmk2 ; enable timer 2 interrupt. set1 busy_o ; if_bit(!f_tushin) ; a=sio0 ; judata=#0 ; if_bit(a.7) ; reread the receive data in reverse. set1 judata.0 ; endif ; if_bit(a.6) ; set1 judata.1 ; endif ; if_bit(a.5) ; set1 judata.2 ; endif ; if_bit(a.4) ; set1 judata.3 ; endif ; if_bit(a.3) ; set1 judata.4 ; endif ; if_bit(a.2) ; set1 judata.5 ; endif ; if_bit(a.1) ; set1 judata.6 ; endif ; if_bit(a.0) ; set1 judata.7 ; endif ; clr1 f_padata ; read in the parity data. cy=ackd ; not1 cy ; f_padata=cy ; endif ; c_work=#0 ; reti ;
213 chapter 8 serial interface application ;********************************************* ; intp1 interrupt servicing (reception) ;********************************************* s_p1 cseg ; intp1: ; sel rb1 ; clr1 tmif2 ; clear timer 2 request flag. clr1 tce2 ; clear timer 2 counter. set1 tce2 ; enable timer operation. while_bit(!tmif2) ; endw ; clr1 tmif2 ; set1 port25 ; set port to an input port. if_bit(!sb0) ; chattering processing of intp1 clr1 acke ; toc1=#10100000b ; set1 pmk1 ; disable intp1 interrupt. sio0=#0ffh ; endif ; clr1 port25 ; set bit 5 of port 2 to an output port. reti ; end
214 78k/0 series application note [memo]
215 chapter 9 a/d converter application chapter 9 a/d converter application the a/d converter in the 78k/0 series has 8-bit resolution and eight channels, and is a successive approximation type. its only operating mode is the select mode, but the start of conversion can also be specified by using an external trigger. in addition, when there is no external trigger, the selected channel is repeated and a/d conversion is performed. the a/d converter is set by the a/d converter mode registers (adm and adm0), a/d converter input selection register (adis), and analog input channel specification register (ads0). cautions 1. adm0 and ads0 are incorporated into the m pd780228 subseries only. 2. the format of the registers incorporated into the m pd780228 subseries differs from that of the m PD78044F, m pd78044h, and m pd780208 subseries. when using any of the sample programs described in this chapter with the m pd780228 subseries, replace the register settings with those for the m pd780228 subseries. * *
216 78k/0 series application note figure 9-1. format of the a/d converter mode register ( m PD78044F, m pd78044h, and m pd780208 subseries) notes 1. set the a/d conversion time to at least 19.1 m s. 2. setting is prohibited because the a/d conversion time is less than 19.1 m s. cautions 1. set bit 0 to 1. 2. when executing the halt or stop instruction, clear bit 7 (cs) of the adm register to stop a/d conversion operations prior to the instruction execution. this reduces the total power consumption of the device in the standby mode, because the a/d converter consumes much power when operating. 3. to restart a/d conversion operation, clear the interrupt request flag (adif) to 0. remark f x : main system clock oscillation frequency 7 cs 6 trg 5 fr1 4 fr0 3 adm3 2 adm2 1 adm1 0 1 symbol adm address ff80h at reset 01h r/w r/w adm3 0 0 0 0 1 1 1 1 adm2 0 0 1 1 0 0 1 1 adm1 0 1 0 1 0 1 0 1 trg 0 1 external trigger selection no external trigger (software start mode) conversion started by an external trigger (hardware start mode) fr1 0 0 1 1 fr0 0 1 0 1 a/d conversion time selection note 1 with f x = 5.0 mhz 160/f x (32.0 s) 80/f x (setting prohibited note 2 ) 200/f x (40.0 s) setting prohibited cs 0 1 a/d converter operation control stop operation start operation analog input channel selection ani0 ani1 ani2 ani3 ani4 ani5 ani6 ani7 with f x = 4.19 mhz 160/f x (38.1 s) 80/f x (19.1 s) 200/f x (47.7 s)
217 chapter 9 a/d converter application figure 9-2. format of the a/d converter mode register ( m pd780228 subseries) notes 1. set the a/d conversion time to at least 14 m s. 2. setting is prohibited because the a/d conversion time is less than 14 m s. caution the results of conversion obtained immediately after setting bit 7 (cs0) to 1 will be unpredictable. remark f x : oscillation frequency of the main system clock * 7 cs0 symbol adm0 address ff80h at reset 00h r/w r/w 6 0 5 fr02 fr02 fr01 fr00 a/d conversion time selection note 1 with f x = 5.0 mhz with f x = 4.19 mhz 144/f x (28.8 s) 120/f x (24 s) 96/f x (19.2 s) 72/f x (14.4 s) 60/f x (setting prohibited note 2 ) 48/f x (setting prohibited note 2 ) 144/f x (34.4 s) 120/f x (28.6 s) 96/f x (22.9 s) 72/f x (17.2 s) 60/f x (14.3 s) 48/f x (setting prohibited note 2 ) setting prohibited 000 001 010 100 4 fr01 3 fr00 2 0 1 0 0 0 101 110 other than the above cs0 a/d converter operation control enable converter operation stop converter operation 1 0
218 78k/0 series application note figure 9-3. format of the a/d converter input selection register ( m PD78044F, m pd78044h, and m pd780208 subseries) cautions 1. set the analog input channel in the following order. <1> set the number of analog input channels in adis. <2> for channels set for analog input in adis, the channel for a/d conversion selects one channel in the a/d converter mode register (adm). 2. regardless of the value of bit 1 (puo1) in the pull-up resistor option register (puo), the channel selected for analog input in adis does not use the on-chip pull-up resistor. 7 0 6 0 5 0 4 0 3 adis3 2 adis2 1 adis1 0 adis0 symbol adis address ff84h at reset 00h r/w r/w adis3 0 0 0 0 0 0 0 0 1 adis2 0 0 0 0 1 1 1 1 0 adis0 0 1 0 1 0 1 0 1 0 adis1 0 0 1 1 0 0 1 1 0 other than the above selection of the number of analog input channels no analog input channels ( p10-p17) 1 channel (ani0, p11-p17) 2 channels (ani0, ani1, p12-p17) 3 channels (ani0-ani2, p13-p17) 4 channels (ani0-ani3, p14-p17) 5 channels (ani0-ani4, p15-p17) 6 channels (ani0-ani5, p16, p17) 7 channels (ani0-ani6, p17) 8 channels (ani0-ani7) setting prohibited
219 chapter 9 a/d converter application figure 9-4. format of the analog input channel specification register (only for the m pd780228 subseries) * 7 0 symbol ads0 address ff81h at reset 00h r/w r/w 6 0 5 0 ads03 ads02 ads01 analog input channel selection 0 0 0 ani0 0 0 0 ani1 0 0 1 ani2 0 1 1 ani6 0 1 1 ani7 other than the above setting prohibited ads00 0 1 0 0 1 4 0 3 ads03 2 ads02 1 ads01 0 ads00 0 0 1 ani3 1 0 1 0 ani4 0 0 1 0 ani5 1
220 78k/0 series application note 9.1 level meter the analog voltage input to the a/d converter is displayed by 16 leds. the led display is arranged in a 4 x 4 matrix. an example using the m PD78044F subseries is described here. because the objective in this example is a level meter, this led display digitally shows the current decibel level of the analog anin pin input. figure 9-5 shows the level meter circuit. figure 9-6 shows the relationship between the a/d conversion result and the number of display digits. figure 9-5. level meter circuit example figure 9-6. a/d conversion result and led display led (number) 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 0ah ?2 12h ?7 20h ?2 2eh ? 39h ? 40h ? 48h ? 51h ? 5bh ? 66h ? 72h ? 80h 0 90h 1 a2h 2 b5h 3 ffh 6 [db] display value display level PD78044F anin p30 p31 p32 p33 p34 p35 p36 p37
221 chapter 9 a/d converter application the level meter in this example operates in the manner described in <1> to <3> . <1> measurement method a/d conversion is performed every 20 ms. the data of the last four conversions are averaged and used in the led display data. <2> display method the led is updated every 20 ms. the led display is a 4 x 4 = 16 dynamic display. 8-bit timer/ event counter 1 (interval time: 2 ms) is used in the dynamic display. <3> peak hold the maximum display level hold during a constant period (1 second) is called the peak hold. even when the display level drops during the constant period, only the maximum display level of the leds is held. as a result, the hold period of the hold level ranges from 20 ms to 1 s. figure 9-7. conceptual diagram of the peak hold (1) package description level : name of led display subroutine dsplev: display level storage area hldlev : hold level storage area ct20ms: 20-ms measurement counter ct1s : 1-s measurement counter ax, hl, bc (subroutine servicing) bank 0: a, hl, b (interrupt servicing) 6 6 6 5 6 4 6 5 7 7 8 8 9 9 9 8 9 7 9 6 9 5 9 5 4 4 4 3 4 3 5 5 6 6 6 2 constant period (1 s) hold level display level
222 78k/0 series application note name use attributes bytes addat a/d conversion value storage saddr 4 dsplev display level storage 1 hldlev hold level storage ct20ms 20-ms measurement counter ct1s 1-s measurement counter digcnt display digit counter dspdat display data storage 4 workct work counter for loop operation 1 name use t20msf set every 20 ms. t1sf set every 1 s. 2 levels, 5 bytes ? a/d converter ? 8-bit timer/event counter 1 ?p3 ? channel selection and operation start of the a/d converter adm=#1000xxx1b ? 2-ms interval for the 8-bit timer/event counter 1 tcl1=#10101010b tmc1=#00000001b cr10=130 ? p3 output mode ? set the p3 output latch to the low level. ? inttm1 interrupt enabled
223 chapter 9 a/d converter application this program is divided into the two parts of a/d conversion processing (subroutine) and led display processing (interrupts). ? a/d conversion processing call level at least once every 20 ms from the main processing. in level processing, a/d conversion is performed when 20 ms have elapsed. ? led display the 4 x 4 matrix led display performs a dynamic display by using interrupt servicing by 8-bit timer/event counter 1 (interval: 2 ms). in addition, in interrupt servicing by 8-bit timer/event counter 1, the flags of t20msf (read in a/d conversion value) and t1sf (end of the hold period) used in a/d conversion are set using the interval (2 ms). (2) use example extrn level,ct20ms,ct1s mov ct20ms,#10 mov ct1s,#50 mov tmc2,#00100110b clr1 tmmk3 p3=#00h ; turn off led display pm3=#00000000b adm=#10000001b ; ani0 pin, start operation tcl1=#10101010b ; set 8-bit timer/event counter 1 to 2 ms. cr10=#130 tmc1=#00000001b clr1 tmmk1 ; enable 8-bit timer/event counter 1 interrupt. ei
224 78k/0 series application note (3) spd chart if : 20 ms has elapsed (t20msf = 1) level then clear t20msf store the a/d conversion value in memory average the a/d conversion values of the last four conversions (for : workct = #0 ; workct < #16 ; workct++) if : conversion result > comparison data for the display level then update the comparison data else break save the display data in memory if : less than 1 second (t1sf = 0) then if : hold level < display level else clear t1sf set the display level in the hold level then set the display level to the hold level convert the display level and hold level into the segment signal combine the digit signal and segment signal and store in memory select register bank 0 output the off signal to digit and segment output the memory contents indicating the digit counter increment the digit counter decrement the 20-ms measurement counter if : 20 ms has elapsed (ct20ms = 0) inttm1 then set the 20-ms counter to 10 set to the 20-ms elapsed state set t20msf decrement the 1-s measurement counter if : 1 second has elapsed (ct1s = 0) then set 50 in the 1-s counter set to the 1-s elapsed state set t1sf
225 chapter 9 a/d converter application (4) program listing public level,hldlev,dsplev,ct20ms,ct1s ad_dat dseg saddr addat: ds 4 ; a/d conversion result storage area dsplev: ds 1 ; display level value hldlev: ds 1 ; hold level value ct20ms: ds 1 ; 20-ms measurement counter ct1s: ds 1 ; 1-s measurement counter digcnt: ds 1 ; display digit counter dspdat: ds 4 ; display data workct: ds 1 ad_flg bseg t20msf dbit ; 20-ms measurement t1sf dbit ; 1-s measurement vetm1 cseg at 16h dw inttm1 ; set vector address of 8-bit timer/event counter 1 ad_seg cseg ;********************************* ;* level meter data setting ;********************************* level: if_bit(t20msf) ; 20-ms check clr1 t20msf a=adcr ; a/d conversion input a<->addat ; save a/d conversion value. a<->addat+1 a<->addat+2 a<->addat+3 ; average the last four a/d conversion values. ax=#0h hl=#addat ; data storage address for(workct=#0;workct<#4;workct++) a+=[hl] hl++ if_bit(cy) ; carry x++ ; high-order digit endif next a<->x c=#4 ; average four conversions ax/=c ; ax/c=ax (quotient)...c (remainder) if(c>=#2) (a) ; remainder processing (carry 3 2) x++ ; carry processing endif hl=#levtbl b=#0 ; conversion result storage register for(workct=#0;workct<#16;workct++) if(x>=[hl+b]) (a) ; data comparison b++ else break endif next
226 78k/0 series application note dsplev=b (a) ; display data decision if_bit(!t1sf) ; 1 s (hold update) x=hldlev (a) ; comparison of hold and display levels if(xx a|=[hl+c] a<->x c++ a|=[hl+c] bc=ax hl=#dspdat ; first digit segment signal setting a=c a&=#0fh a|=#00010000b ; digit signal setting [hl]=a hl++ a=c ; second digit segment signal setting a>>=1 a>>=1 a>>=1 a>>=1 a&=#0fh a|=#00100000b ; digit signal setting [hl]=a hl++ a=b ; third digit segment signal setting a&=#0fh a|=#01000000b ; digit signal setting [hl]=a hl++ a=b ; fourth digit segment signal setting a>>=1 a>>=1 a>>=1 a>>=1 a&=#0fh a|=#10000000b ; digit signal setting [hl]=a endif
227 chapter 9 a/d converter application ret levtbl: db 0ah db 12h db 20h db 2eh db 39h db 40h db 48h db 51h db 5bh db 66h db 72h db 80h db 90h db 0a2h db 0b5h db 0ffh dsptbl: dw 0000000000000000b dw 0000000000000001b dw 0000000000000011b dw 0000000000000111b dw 0000000000001111b dw 0000000000011111b dw 0000000000111111b dw 0000000001111111b dw 0000000011111111b dw 0000000111111111b dw 0000001111111111b dw 0000011111111111b dw 0000111111111111b dw 0001111111111111b dw 0011111111111111b dw 0111111111111111b dw 1111111111111111b hldtbl: dw 0000000000000000b dw 0000000000000001b dw 0000000000000010b dw 0000000000000100b dw 0000000000001000b dw 0000000000010000b dw 0000000000100000b dw 0000000001000000b dw 0000000010000000b dw 0000000100000000b dw 0000001000000000b dw 0000010000000000b dw 0000100000000000b dw 0001000000000000b dw 0010000000000000b dw 0100000000000000b dw 1000000000000000b $eject
228 78k/0 series application note ;************************************ ;* level meter output ;************************************ tm1_seg cseg inttm1: sel rb0 p3=#00000000b ; turn off digit and segment signals. hl=#dspdat b=digcnt (a) p3=[hl+b] (a) digcnt++ digcnt&=#00000011b ct20ms-- ; 20 ms ? if(ct20ms==#0) ct20ms=#10 ; initial counter setting set1 t20msf ct1s-- ; 1 s ? if(ct1s==#0) ct1s=#50 ; initial counter setting set1 t1sf endif endif reti
229 chapter 9 a/d converter application 9.2 thermometer in this example, a thermistor (6 k w /0 c) is used in a temperature sensor and measures temperatures between C20 c and +50 c. changes in resistance corresponding to the temperature of the thermistor can be represented in the following way. r = r 0 exp {b (1/tC1/t 0 ) } r : resistance at some temperature t [ k] t : any temperature [ k] r 0 : resistance at the reference temperature t 0 [ k] t 0 : reference temperature [ k] b : constant determined from the reference temperature t 0 [ k] and t 0 [ k] however, the b constant is not constant and is changed by the temperature. the b constant is transformed in the above equation and can be determined by the following equation. b = 1 in r (1/tC1/t 0 )r 0 an example circuit is shown in figure 9-8. this circuit is set so that 0 v is input at C20 c and 5 v are input at +50 c. figure 9-8. thermometer circuit example th anin PD78044F
230 78k/0 series application note in this example circuit, because the thermistor characteristics are not linear, the input analog voltage is changed into a temperature from C20 c to +50 c by comparing the voltage with table data and not by a calculation. this conversion result is saved in the ram (dspdat) as two bcd digits. figure 9-9 shows the thermistor characteristics. table 9-1 shows the relationship between the temperature and the a/d conversion value. also, the measurement method changes the average of the four conversion results into a temperature. therefore, the conversion result is stored in the display area. consequently, one datum in four is updated. for example, when measurement processing is performed every 250 ms, the display update period becomes one second. figure 9-9. temperature and output characteristics 100 90 80 70 60 50 40 30 20 10 0 (%) ?0 ?0 0 10 20 30 40 50 temperature ( c) output characteristics percentage
231 chapter 9 a/d converter application table 9-1. a/d conversion values and temperatures conversion temperature conversion temperature conversion temperature conversion temperature value [ c] value [ c] value [ c] value [ c] 00 C20.0 38 C2.5 82 15.5 cb 33.5 01 C19.5 3c C1.5 86 16.5 ce 34.5 04 C18.5 40 C0.5 8b 17.5 d2 35.5 07 C17.5 44 0.5 8f 18.5 d6 36.5 0a C16.5 48 1.5 93 19.5 d9 37.5 0c C15.5 4c 2.5 97 20.5 dc 38.5 0f C14.5 50 3.5 9b 21.5 e0 39.5 12 C13.5 54 4.5 9f 22.5 e3 40.5 16 C12.5 58 5.5 a3 23.5 e7 41.5 19 C11.5 5c 6.5 a8 24.5 ea 42.5 1c C10.5 60 7.5 ac 25.5 ed 43.5 1f C9.5 64 8.5 b0 26.5 f0 44.5 23 C8.5 69 9.5 b4 27.5 f3 45.5 26 C7.5 6d 10.5 b7 28.5 f6 46.5 2a C6.5 71 11.5 bb 29.5 f9 47.5 2d C5.5 75 12.5 bf 30.5 fc 48.5 31 C4.5 7a 13.5 c3 31.5 fe 49.5 35 C3.5 7e 14.5 c7 32.5 ff 50.0 (1) package description thmeter : name of the thermometer subroutine dspdat : display data storage area cntpro : number of inputs test counter minusf : minus temperature display flag t250msf : flag for setting 250 ms ax, bc, hl
232 78k/0 series application note name use attributes bytes addat a/d conversion value storage saddr 4 dspdat display data storage 2 cntpro number of inputs test counter 1 workct work counter for loop operation name use t250msf when set, measurement processing is executed. minusf set when the temperature is minus. 1 level, 2 bytes a/d converter channel selection and operation start for a/d converter adm=#1000xxx1b in timer processing, set the t250msf flag in each measurement period. then, call thmeter at least once during the measurement period.
233 chapter 9 a/d converter application (2) use example extrn thmeter,dspdat,cntpro extbit minusf,t250msf ad_dat dseg saddr ct250ms:ds 1 ; 250-ms measurement counter ledd: ds 4 ; led display area digct: ds 1 ; led display digit counter vetm3 cseg at 12h dw inttm3 ; vector address setting of the watch timer mov tmc2,#00100110b ; 1.95-ms setting for the watch timer clr1 tmmk3 : : ct250ms=#128 cntpro=#4 adm=#10000011b ; ani1 pin, operation start : : ;************************************** ; watch timer interrupt servicing ; 1.95-ms interval ;************************************** inttm3: ; 1.95-ms interrupt servicing : : dbnz ct250ms,$rtntm3 mov ct250ms,#128 ; 250-ms had elapsed set1 t250msf rtntm3: : : reti
234 78k/0 series application note (3) spd chart if : 250 ms has elapsed (t250ms = 1) thmeter then clear t250ms save the a/d conversion value in memory if : 4 conversions are saved in memory then average four a/d conversion values (for : workct = #0 ; workct < #70 ; workct++) then update comparision data if : conversion result > comparison data for temperature conversion else break then set in the minus state set minusf if : temperature data is a negative value convert the temperature data into a decimal number and save in memory
235 chapter 9 a/d converter application (4) program listing public thmeter,dspdat,cntpro,t250msf,minusf ad_dat dseg saddr addat: ds 4 ; a/d conversion result storage area dspdat: ds 2 ; display data cntpro: ds 1 ; test the number of inputs. workct: ds 1 ad_flg bseg t250msf dbit ; 250-ms setting minusf dbit ; negative data setting th_seg cseg ;******************************** ;* temperature data setting ;******************************** thmeter: if_bit(t250msf) ; 250 ms clr1 t250msf a=adcr a<->addat a<->addat+1 a<->addat+2 a<->addat+3 cntpro-- if(cntpro==#0) cntpro=#4 ax=#0h hl=#addat ; data storage address for(workct=#0;workct<#4;workct++) a+=[hl] hl++ if_bit(cy) ; carry present. x++ ; carry endif next a<->x c=#4 ax/=c ; ax/c=ax (quotient)...c (remainder) if(c>=#2) (a) ; remainder processing (carry 3 2) x++ ; carry processing endif a=x ; convert to temperature data. b=#0 hl=#thrtbl if(a==#0ffh) b=#70 else for(workct=#0;workct<#70;workct++) if(x>=[hl+b]) (a) b++ else break endif next
236 78k/0 series application note endif clr1 minusf a=#20 ; temperature data 20 b-=a if_bit(cy) ; to decimal conversion set1 minusf a=#0 a-=b ; take the absolute value of data a<->b endif x=#0 ; decimal conversion a=b a<->x c=#10 ax/=c ; temperature data/10 dspdat=c (a) ; update display data. (dspdat+1)=x (a) endif endif ret
237 chapter 9 a/d converter application thrtbl: ; db 1 ; C19.5 db 4 ; C18.5 db 7 ; C17.5 db 0ah ; C16.5 db 0ch ; C15.5 db 0fh ; C14.5 db 12h ; C13.5 db 16h ; C12.5 db 19h ; C11.5 db 1ch ; C10.5 db 1fh ; C9.5 db 23h ; C8.5 db 26h ; C7.5 db 2ah ; C6.5 db 2dh ; C5.5 db 31h ; C4.5 db 35h ; C3.5 db 38h ; C2.5 db 3ch ; C1.5 db 40h ; C0.5 db 44h ; +0.5 db 48h ; 1.5 db 4ch ; 2.5 db 50h ; 3.5 db 54h ; 4.5 db 58h ; 5.5 db 5ch ; 6.5 db 60h ; 7.5 db 64h ; 8.5 db 69h ; 9.5 db 6dh ; 10.5 db 71h ; 11.5 db 75h ; 12.5 db 7ah ; 13.5 db 7eh ; 14.5 db 82h ; 15.5 db 86h ; 16.5 db 8bh ; 17.5 db 8fh ; 18.5 db 93h ; 19.5 db 97h ; 20.5 db 9bh ; 21.5 db 9fh ; 22.5 db 0a3h ; 23.5 db 0a8h ; 24.5 db 0ach ; 25.5 db 0b0h ; 26.5 db 0b4h ; 27.5 db 0b7h ; 28.5 db 0bbh ; 29.5 db 0bfh ; 30.5 db 0c3h ; 31.5 db 0c7h ; 32.5 db 0cbh ; 33.5 db 0ceh ; 34.5 db 0d2h ; 35.5 db 0d6h ; 36.5
238 78k/0 series application note db 0d9h ; 37.5 db 0dch ; 38.5 db 0e0h ; 39.5 db 0e3h ; 40.5 db 0e7h ; 41.5 db 0eah ; 42.5 db 0edh ; 43.5 db 0f0h ; 44.5 db 0f3h ; 45.5 db 0f6h ; 46.5 db 0f9h ; 47.5 db 0fch ; 48.5 db 0feh ; 49.5
239 chapter 9 a/d converter application 9.3 analog key input the a/d converter is used to read in 16 keys. in order to perform key input, the circuit is configured so that when a key is pressed, a voltage unique to that key is input into the a/d converter. in this example, because 16 different keys are read in, the v dd voltage is divided into 16 levels. this voltage is converted into a key code. table 9-2 shows the relationship between the input voltage and key code (00h-0fh). when there is no key input, the key code is 10h. table 9-2. input voltages and key codes input voltage (v) a/d conversion value key code gnd 00-07h 00h 1/16v dd 08-17h 01h 2/16v dd 18-27h 02h 3/16v dd 28-37h 03h 4/16v dd 38-47h 04h 5/16v dd 48-57h 05h 6/16v dd 58-67h 06h 7/16v dd 68-77h 07h 8/16v dd 78-87h 08h 9/16v dd 88-97h 09h 10/16v dd 98-a7h 0ah 11/16v dd a8-b7h 0bh 12/16v dd b8-c7h 0ch 13/16v dd c8-d7h 0dh 14/16v dd d8-e7h 0eh 15/16v dd e8-f7h 0fh v dd f8-ffh 10h figure 9-10 shows an example circuit implementing the relationship between the input voltage and the key code. however, when two or more keys are pressed in this circuit, the key having the smaller code is given priority and read in.
240 78k/0 series application note figure 9-10. analog key input circuit example resistors r0 to r15 used in the circuit shown in figure 9-10 can be determined from the following equation. s r k = n x r0 16 C n table 9-3 shows the resistances of r1 to r15 based on this equation when r0 was 1 k w . (because the resistances are based on the color-coded display on commercial resistors, the calculation results may differ.) table 9-3. resistances of r1 to r15 resistor number resistance ( w ) resistor number resistance ( w ) resistor number resistance ( w ) r1 68 r6 150 r11 560 r2 75 r7 180 r12 750 r3 82 r8 220 r13 1.3 k r4 100 r9 270 r14 2.7 k r5 120 r10 390 r15 8.2 k in this program, the analog voltage that was input is converted into a key code listed in table 9-2. after chattering is absorbed, the code is saved in ram. chattering absorption uses a technique where a key becomes valid when the key code matches five consecutive times. for example, when sampling is performed every 5 ms, chattering lasting 20 ms to 25 ms is absorbed. when the key input changed, the key change flag (keychg) is set. n k=1 k0 k1 k2 k14 k15 v dd r0 r1 r2 r14 r15 anin PD78044F
241 chapter 9 a/d converter application (1) package description akeyin : name of analog key input subroutine keydat : key code storage area pastdt : key code storage area for chattering absorption chatct : chattering absorption counter keychg : key change test flag chtendf : end of chattering absorption test flag keyoff : key code when there is no key input a name use attributes bytes pastdat key code storage for chattering absorption saddr 1 keydat key code storage chatcnt chattering counter name use keychg set when the key changes chtendf set at the end of chattering absorption 1 level, 2 bytes a/d converter channel selection and operation start of a/d converter adm=#1000xxx1b ? call akeyin in each constant interval. ? read in the key code after testing the key change flag. also, because the key change flag is not cleared in the subroutine, clear after testing the flag.
242 78k/0 series application note (2) use example extrn akeyin,keydat,pastdt,chatct extrn keyoff extbit keychg,chtendf vetm3 cseg at 12h dw inttm3 ; vector address setting of the watch timer maindat dseg saddr ct5ms: ds 1 tmc2=#00100110b clr1 tmmk3 ct5ms=#3 keydat=#keyoff ; set the off data in the key data. pastdt=#keyoff chatct=#chaval ; set the chattering count to 5 times. clr1 chtendf clr1 keychg adm=#10000101b ; ani2 pin, operation start ei : : if_bit(keychg) ; did the key change? clr1 keychg ; key input processing endif : : ;*************************************** ; watch timer interrupt servicing ; 1.95-ms interval ;*************************************** inttm3: ; 1.95-ms interrupt servicing : : dbnz ct5ms,$rtntm3 mov ct5ms,#3 ; 1.95 ms x 3 elapsed call !akeyin rtntm3: : : reti
243 chapter 9 a/d converter application (3) spd chart adjust and input of a/d conversion value (add 8) if : there is an overflow decode key akeyin then else set to the state where there is no input key then else if : absorbing chattering if : there is no key input change update the comparison key code set to the start chattering absorption state clear chtendf then if : chattering absorption finished then set to the chattering absorption state set chtendf if : there is a change to a valid key then update key code set to key change state set keychg
244 78k/0 series application note (4) program listing public akeyin,keydat,pastdt public chatct,keyoff public keychg,chtendf ak_dat dseg saddr keydat: ds 1 ; key data storage area pastdt: ds 1 ; chattering key data chatct: ds 1 ; chattering counter ak_flg bseg keychg dbit ; key change. chtendf dbit ; end of chattering absorption state keyoff equ 10h ; off key data chaval equ 5 ; chattering absorption count ak_seg cseg ;************************** ;* analog key input ;************************** akeyin: a=adcr ; a/d conversion input a+=#8 ; data adjustment if_bit(cy) a=#keyoff ; set to the no input key state. else a>>=1 ; decode key a>>=1 a>>=1 a>>=1 a&=#0fh endif if(a==pastdt) ; no key change if_bit(!chtendf) ; absorbing chattering chatct-- ; end of chattering absorption if(chatct==#0) set1 chtendf ; set to the end of chattering absorption state a=pastdt if(a!=keydat) ; there is a valid key change. keydat=a ; update key data. set1 keychg ; set to the key change state. endif endif endif else pastdt=a ; update previous key data. chatct=#chaval-1 ; start chattering absorption. clr1 chtendf endif ret
245 chapter 9 a/d converter application 9.4 4-channel input a/d conversion this section describes an a/d conversion method where four channels are scanned. a/d conversion is started by a software start. analog voltages input to the four selected channels undergo a/d conversion. the conversion result of each channel is saved in ram. an interrupt request is generated by 8-bit timer/event counter 1 and the conversion result is read into processing for the interrupt request and channel conversion is performed. because the time set for 8-bit timer/event counter 1 is 10 ms, measuring the waiting time for a/d conversion is not necessary. caution when the interrupt time changes, set the following. ? the timer is set to a value longer than a/d-conversion-completion-time + interrupt-return-time + interrupt-servicing-time ? flags are tested at the end of conversion. figure 9-11. timing chart in the 4-channel scanning mode (1) package description ? output parameters m_ch0: stores the conversion result of channel 0 m_ch1: stores the conversion result of channel 1 m_ch2: stores the conversion result of channel 2 m_ch3: stores the conversion result of channel 3 inttm2 adcr adin 10 ms ani0 ani1 ani2 ani3 ani0 ani1 ani2 ani3 ani0 123012301 0
246 78k/0 series application note a name use attributes bytes m_ch0 storage area for channel 0 conversion result saddr 1 m_ch1 storage area for channel 1 conversion result saddr 1 m_ch2 storage area for channel 2 conversion result saddr 1 m_ch3 storage area for channel 3 conversion result saddr 1 m_mode mode storage area saddr 1 1 level, 3 bytes ? a/d converter ? 8-bit timer/event counter 1 ? port 1 (p10-p13) ? channel selection and operation start of the a/d converter adm=#1000xxxxb ? channel number selection of a/d converter adis=#00000100b ? 10-ms interval for 8-bit timer/event counter 1 tcl1=#00001101b tmc1=#00000001b cr10=#81 ? tmmk1 interrupt enabled
247 chapter 9 a/d converter application (2) use example extrn m_ch0,m_ch1,m_ch2,m_ch3,m_mode ;************************************** ; initialize ;************************************** m4 cseg ; res_sta: sel rb0 ; di ; . . adm=#10000001b ; a/d operation start, no external trigger, channel 0 selected adis=#00000100b ; analog input, 4 channels selected cr10=#81 ; modulo register 81 setting tcl1=#00001101b ; count/clock 8.2 khz tmc1=#00000001b ; enable 8 bit/timer/register 1 operation clr1 tmif1 ; clear timer 1 interrupt request flag. clr1 tmmk1 ; enable timer 1 interrupt. ei ; m_mode=#0 ; set the initial value (0 channels) in the mode area . . while(forever) ; . . a=m_ch0 ; a <- channel 0 data . . a=m_ch1 ; a <- channel 1 data . . a=m_ch2 ; a <- channel 2 data . . a=m_ch3 ; a <- channel 3 data . . (3) spd chart [a/d conversion processing] read in the conversion result of the channel in the previous a/d conversion change the channel adm<-changed channel selection kasan
248 78k/0 series application note (4) program listing ; ;************************************** ; a/d conversion ;************************************** ; $pc(044a) ; ; public m_ch0,m_ch1,m_ch2,m_ch3,m_mode ; ; veintm1 cseg at 16h dw kasan ;************************************** ; ram definition ;************************************** dseg saddr m_ch0: ds 1 ; ram area for channel 0 addition m_ch1: ds 1 ; ram area for channel 1 addition m_ch2: ds 1 ; ram area for channel 2 addition m_ch3: ds 1 ; ram area for channel 3 addition m_mode: ds 1 ; mode storage area ; cseg ; kasan: sel rb2 ; switch to bank 2. switch(m_mode) ; which channel is currently selected? case 0: ; channel 0: m_ch0=adcr (a) ; transfer conversion result to ram m_mode++ ; adm=#10000011b ; change channel selection to 1. break ; case 1: ; channel 1: m_ch1=adcr (a) ; transfer conversion result to ram m_mode++ ; adm=#10000101b ; change channel selection to 2. break ; case 2: ; channel 2: m_ch2=adcr (a) ; transfer conversion result to ram m_mode++ ; adm=#10000111b ; change channel selection to 3. break ; case 3: ; channel 3: m_ch3=adcr (a) ; transfer conversion result to ram m_mode=#0 ; adm=#10000001b ; change channel selection to 0. break ; ends ; reti ; end
249 chapter 10 applications of fip controller/driver chapter 10 applications of fip controller/driver the functions of the fip controller/driver are listed below. the differences between the m PD78044F, m pd78044h, m pd780208, and m pd780228 subseries are listed in table 10-1. (1) segment signal output (dma operation) by automatically reading display data and automatic output of digit signals (2) display mode register controlling fip (fluorescent indicator panel) (see table 10-1.) (3) those pins not used for fip display can be used either as output port or i/o port pins (however, pins fip0 through fip12 of the m pd780208 subseries and pins fip0 through fip15 of the m pd780228 subseries are dedicated to display output). (4) brightness can be set to one of eight steps by using display mode register 1 (dspm1). (5) hardware for key scan application ? generates an interrupt request signal (intks) indicating the key scan timing ? key scan signals are output from segment output pins if data for key scanning is set to port (see table 10-1). ? key scan data output timing can be detected by key scan flag (ksf). ? whether the key scan timing is inserted can be selected (only for the m pd780228 subseries). (6) high-voltage output buffer directly driving fip (7) pull-down resistor can be connected by mask option to display output pins. (8) any digit signal output timing can be set by selecting display mode 2 with display mode register 0 (dspm0) ( m pd780208 subseries only). caution the format of the registers incorporated into the m pd780228 subseries differs from that of the registers incorporated into the m PD78044F, m pd78044h, and m pd780208 subseries. when using any of the sample programs described in this chapter with the m pd780228 subseries, replace the register settings with those for the m pd780228 subseries. * * *
250 78k/0 series application note table 10-1. differences between m PD78044F, m pd78044h, m pd780208, and m pd780228 subseries subseries m PD78044F m pd78044h m pd780208 m pd780228 item subseries subseries subseries subseries number of segments 9-24 9-40 up to 48 for total number of number of digits 2-16 segments and digits display mode ? segment type ? segment type ? character type ? type that a segment extends two or more grids multiplexed key scan port ports 11 and 12 ports 8-12 ports 7-10 controlling register display mode registers 0 and 1 display mode registers 0-2 (dspm0 and dspm1) (dspm0-dspm2) *
251 chapter 10 applications of fip controller/driver figure 10-1. format of display mode register 0 ( m PD78044F and m pd78044h subseries) notes 1. bit 7 (ksf) is read-only. 2. specify a value in accordance with the oscillation frequency of the main system clock (f x ). the noise eliminator can be used during fip display operation. caution when using the fip controller/driver with a main system clock of 1.25 mhz, use the main system clock (tcl24 (bit 4 of timer clock selection register 2 (tcl2)) = 0) for the watch timer. remark f x : oscillation frequency of the main system clock ksf 7 dspm06 6 0 5 0 4 segs3 3 segs2 2 segs1 1 segs0 0 segs3 segs2 segs1 segs0 number of display segments 00009 000110 001011 001112 010013 010114 011015 011116 100017 100118 101019 101120 110021 110122 111023 111124 dspm06 mode setting for the noise eliminator of the subsystem clock note 2 0 2.5 mhz < f x 5.0 mhz 1 1.25 mhz < f x 2.5 mhz ksf timing status 0 display timing 1 key scan timing dspm0 symbol ffa0h address 00h at reset r/w note 1 r/w < <
252 78k/0 series application note figure 10-2. format of display mode register 0 ( m pd780208 subseries) (1/2) note if the total number of digits and segments exceeds 53, digits have precedence over segments. ksf 7 dspm06 6 dspm05 5 segs4 4 segs3 3 segs2 2 segs1 1 segs0 0 dspm0 symbol ffa0h address 00h at reset r/w r/w segs3 segs2 segs1 segs0 number of display segments (display mode 1) 00009 000110 001011 001112 010013 010114 011015 011116 100017 100118 101019 101120 110021 110122 111023 111124 number of display outputs (display mode 2) 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 000025 25 000126 26 001027 27 001128 28 010029 29 010130 30 011031 31 011132 32 100033 33 100134 34 101035 35 101136 36 110037 37 110138 note 38 111039 note 39 1 segs4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11140 note 40 r/w
253 chapter 10 applications of fip controller/driver figure 10-2. format of display mode register 0 ( m pd780208 subseries) (2/2) notes 1. bit 7 (ksf) is read-only. 2. specify a value in accordance with the oscillation frequency of the main system clock (f x ). the noise eliminator can be used during fip display operation. 3. when f x is used from above 1.25 mhz to 2.5 mhz, set 1 in dspm06 before fip display. caution when using the fip controller/driver with a main system clock of 1.25 mhz, use the main system clock (tcl24 (bit 4 of timer clock selection register 2 (tcl2)) = 0) for the watch timer. remark f x : oscillation frequency of the main system clock ksf 7 dspm06 6 dspm05 5 segs4 4 segs3 3 segs2 2 segs1 1 segs0 0 ksf timing status 0 display timing 1 key scan timing dspm0 symbol ffa0h address 00h at reset r/w note 1 r/w r dspm06 mode setting for the noise eliminator of the subsystem clock note 2 0 2.5 mhz < f x 5.0 mhz 1 1.25 mhz < f x 2.5 mhz note 3 r/w dspm05 setting of display mode 0 display mode 1 (segment/character type) 1 display mode 2 (type that a segment extends two or more grids) r/w < <
254 78k/0 series application note figure 10-3. format of display mode register 0 ( m pd780228 subseries) cautions 1. always set bit 6 to 0. 2. when bit 7 (dspen) is 1, do not write data into bits other than dspen. 3. the output latch of the port multiplexed with the pins used for fip output must be set to 0. * 7 dspen symbol dspm0 address ff90h at reset 10h r/w r/w 6 0 5 fout5 fout5 fout4 fout3 number of fip output pins 0 1 0 17-24 0 1 1 25-32 1 0 0 33-40 fout2 1 1 1 4 fout4 3 fout3 2 fout2 1 fout1 0 fout0 1 0 1 41-48 1 fout1 1 1 1 1 fout0 1 1 dspen enabling or disabling fip display 0 enable fip display 1 disable fip display 1 1 other than the above setting prohibited
255 chapter 10 applications of fip controller/driver figure 10-4. format of display mode register 1 ( m PD78044F and m pd78044h subseries) note when display is disabled, a port output latch can be operated to enable static display. remark f x : oscillation frequency of the main system clock digs3 7 digs2 6 digs1 5 digs0 4 dims3 3 dims2 2 dims1 1 dims0 0 dims0 display cycle selection 0 1024/f x as 1 display cycle (one display cycle is 204.8 s at 5.0 mhz.) 1 2048/f x as 1 display cycle (one display cycle is 409.6 s at 5.0 mhz.) dspm1 symbol ffa1h address 00h at reset r/w r/w dims3 dims2 dims1 cut width of the digit signal 0 0 0 1/16 0 0 1 2/16 0 1 0 4/16 0 1 1 6/16 1 0 0 8/16 1 0 1 10/16 1 1 0 12/16 1 1 1 14/16 digs3 digs2 digs1 digs0 number of display digits 0000 disabled display (static display) note 00012 00103 00114 01005 01016 01107 01118 10009 100110 101011 101112 110013 110114 111015 111116
256 78k/0 series application note figure 10-5. format of display mode register 1 ( m pd780208 subseries) note when display is disabled, a port output latch can be operated to enable static display. remark f x : oscillation frequency of the main system clock dspm05 : bit 5 of display mode register 0 digs3 7 digs2 6 digs1 5 digs0 4 dims3 3 dims2 2 dims1 1 dims0 0 dims0 setting of display mode cycle 0 1024/f x as 1 display cycle (one display cycle is 204.8 s at 5.0 mhz.) 1 2048/f x as 1 display cycle (one display cycle is 409.6 s at 5.0 mhz.) dspm1 symbol ffa1h address 00h at reset r/w r/w dims3 dims2 dims1 cut width of the fip output signal 0 0 0 1/16 0 0 1 2/16 0 1 0 4/16 0 1 1 6/16 1 0 0 8/16 1 0 1 10/16 1 1 0 12/16 1 1 1 14/16 digs3 digs2 digs1 digs0 number of display digits (display mode 1) dspm05 = 0 0000 disabled display (static display) note 00012 00103 00114 01005 01016 01107 01118 10009 100110 101011 101112 110013 110114 111015 111116 number of display patterns (display mode 2) dspm05 = 1 disabled display (static display) note 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
257 chapter 10 applications of fip controller/driver figure 10-6. format of display mode register 1 ( m pd780228 subseries) caution when bit 7 (dspen) of display mode register 0 (dspm0) is 1, do not write data into display mode register 1 (dspm1). * 7 fblk2 symbol dspm1 address ff91h at reset 01h r/w r/w 6 fblk1 5 fblk0 fpat4 fpat3 fpat2 number of display patterns 000 2 000 3 000 4 fpat1 0 1 1 4 fpat4 3 fpat3 2 fpat2 1 fpat1 0 fpat0 001 5 0 fpat0 1 0 1 0 001 6 01 001 7 10 001 8 11 010 9 00 fblk2 fblk1 fblk0 blanking width for the fip output signal 000 001 010 011 100 101 110 111 1/16 2/16 4/16 6/16 8/16 10/16 12/16 14/16 010 10 01 010 11 10 010 12 11 011 13 00 011 14 01 011 15 10 011 16 11 other than the above setting prohibited
258 78k/0 series application note figure 10-7. format of display mode register 2 ( m pd780208 subseries) (1/2) 0 7 0 6 useg5 5 useg4 4 useg3 3 useg2 2 useg1 1 useg0 0 dspm2 symbol ffa1h address 00h at reset r/w r/w useg5 useg4 useg3 useg2 0000 0000 0000 0000 0001 0001 0001 0001 0010 0010 0010 0010 0011 0011 0011 0011 useg1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 useg0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 number of write mask bits none 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 01000016 01000117 01001018 01001119 01010020 01010121 01011022 01011123 01100024 01100125 01101026 01101127 01110028 01110129 01111030 01111131
259 chapter 10 applications of fip controller/driver figure 10-7. format of display mode register 2 ( m pd780208 subseries) (2/2) 0 7 0 6 useg5 5 useg4 4 useg3 3 useg2 2 useg1 1 useg0 0 dspm2 symbol ffa1h address 00h at reset r/w r/w useg5 useg4 useg3 useg2 1000 1000 1000 1000 1001 1001 1001 1001 other than the above useg1 0 0 1 1 0 0 1 1 useg0 0 1 0 1 0 1 0 1 number of write mask bits 32 33 34 35 36 37 38 39 setting prohibited
260 78k/0 series application note figure 10-8. format of display mode register 2 ( m pd780228 subseries) cautions 1. always set 0 in bits 2 to 5. 2. when bit 7 (dspen) of display mode register 0 (dspm0) is 1, do not write data into display mode register 2 (dspm2). remarks 1. f x : oscillation frequency of the main system clock 2. the values in parentheses apply to operation with f x = 5.0 mhz. * 7 ksf symbol dspm2 address ff92h at reset 00h r/w r/w 6 ksm 5 0 fcyc1 fcyc0 display cycle 002 12 f x (819.2 s) 012 11 /f x (409.6 s) 102 10 /f x (204.8 s) 1 1 setting prohibited 4 0 3 0 2 0 1 fcyc1 0 fcyc0 ksm selection of key scan cycle insertion 0 insert a key scan cycle 1 insert no key scan cycle ksf status of the key scan cycle 0 during a cycle other than the key scan cycle 1 during the key scan cycle
261 chapter 10 applications of fip controller/driver figure 10-9. fip controller operation timing n : number of display digits - 1 (2 to 16 digits selectable by display mode register 1 (dspm1) t dsp : one display cycle (1024/f x (244 m s at 4.19 mhz) or 2048/f x (488 m s at 4.19 mhz)) t ks : key scan timing (t ks = t dsp ) t cyt : display cycle (t cyt = t dsp x (number of digits + 1)) t dig : digit signal pulse width (eight types, selectable with display mode register 1 (dspm1)) digit signal fip0 fip1 fip2 fipn key scan flag (ksf) segment signal t ks key scan timing t dsp 1 display cycle t cyt t dig can be changed at any time
262 78k/0 series application note 10.1 12-digit display for fip and key input this section shows an example of processing an fip having 12 digits by 9 segments and 8 x 4 key inputs by using the fip controller/driver of the m PD78044F subseries. in this example, a key of the 8 x 4 key matrix that has been pressed is displayed on the first digit of the fip (to in figure 10-10), and the data that has already been displayed is shifted one column to the left. figure 10-10 shows the configuration. figure 10-10. configuration of 12-digit fip display and key input p80 p81 p90 p91 p92 p93 p94 p95 p96 p97 p100 p101 p102 p103 p104 p105 p106 p107 p110 p111 p112 p113 p114 p115 p116 p117 p120 p121 p122 p123 PD78044F s0 s1 s2 s3 s4 s5 s6 s7 s8 t11 t10 t9 t8 t7 t6 t5 t4 t3 t2 t1 t0 fip display =
263 chapter 10 applications of fip controller/driver 10.1.1 12-digit fip display (1) setting the number of segments and number of digits with the circuit shown in figure 10-10, twelve digits are displayed using eight key scan signals. the 9 segment x 12 digit fip display mode is set. nine segments is the minimum value for the selected number. figure 10-11 shows the pin layout according to the number of display digits for which nine segments are displayed.
264 78k/0 series application note figure 10-11. pin layout for 9-segment display : logical add (or) : area used by this program pin name fip0/p80 fip1/p81 fip2/p90 fip3/p91 fip4/p92 fip5/p93 fip6/p94 fip7/p95 fip8/p96 fip9/p97 fip10/p100 fip11/p101 fip12/p102 fip13/p103 fip14/p104 fip15/p105 fip16/p106 fip17/p107 fip18/p110 fip19/p111 fip20/p112 fip21/p113 fip22/p114 fip23/p115 fip24/p116 fip25/p117 fip26/p120 fip27/p121 fip28/p122 fip29/p123 fip30/p124 fip31/p125 fip32/p126 display stops p80 p81 p90 p91 p92 p93 p94 p95 p96 p97 p100 p101 p102 p103 p104 p105 p106 p107 p110 p111 p112 p113 p114 p115 p116 p117 p120 p121 p122 p123 p124 p125 p126 p127 2 t0 t1 p90 p91 p92 p93 p94 p95 p96 p97 s0 s1 s2 s3 s4 s5 s6 s7 s8 p110 p111 p112 p113 p114 p115 p116 p117 p120 p121 p122 p123 p124 p125 p126 p127 9 t0 t1 t2 t3 t4 t5 t6 t7 t8 p97 s0 s1 s2 s3 s4 s5 s6 s7 t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 s0 s1 s2 s3 s4 s5 s6 s7 t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 s0 s1 s2 s3 s4 s5 s6 t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 s0 s1 s8 p110 p111 p112 p113 p114 p115 p116 p117 p120 p121 p122 p123 p124 p125 p126 p127 10 s8 p110 p111 p112 p113 p114 p115 p116 p117 p120 p121 p122 p123 p124 p125 p126 p127 11 s7 p110 s8 p111 p112 p113 p114 p115 p116 p117 p120 p121 p122 p123 p124 p125 p126 p127 p113 p114 p115 p116 p117 p120 p121 p122 p123 p124 p125 p126 p127 16 s2 p110 s3 p111 s4 p112 s5 p113 s6 p114 s7 p115 s8 p116 p117 p120 p121 p122 p123 p124 p125 p126 p127 fip33/p127 selected number of display digits 12 t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 s0 s1 s2 s3 s4 s5 s6 p110 s7 p111 s8 p112
265 chapter 10 applications of fip controller/driver (2) display data memory the display data memory is an area that stores the segment data to be displayed on an fip. this area is mapped to addresses fa50h through fa7fh. the fip controller reads data from this area independently of instruction operation to enable the display of the fip and outputs a segment signal synchronized with digit signals (dma operation). any unused portion of this area can be used as an ordinary ram area. when a key is scanned, all digit signals are cleared to 0, and the data of the output latches of ports 11 and 12 are output to the fip18/p110 through pins fip33/p127. the shaded portion in figure 10-12 indicates the area used by this program. figure 10-12. relationship between contents of display data memory and segment output 0 0 00000000000 00000000000 s23 s16 s15 s8 s7 s0 fa50h fa51h fa52h fa53h fa54h fa55h fa56h fa57h fa58h fa59h fa5ah fa5bh fa5ch fa5dh fa5eh fa5fh fa60h fa61h fa62h fa63h fa64h fa65h fa66h fa67h fa68h fa69h fa6ah fa6bh fa6ch fa6dh fa6eh fa6fh fa7ch fa7dh fa7eh fa7fh t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t ks fa70h fa71h fa72h fa73h fa74h fa75h fa76h fa77h fa78h fa79h fa7ah fa7bh bit 7 0 7 0 7 0 timing output
266 78k/0 series application note (3) display to display an fip, output the data set for a display digit as the digit signals and write the data to be displayed as segment signals (i.e., to the display data memory). as an example, the setting of display mode registers 0 and 1 when 9 segments and 12 digits are to be displayed is shown below. figure 10-13 shows an example display based on this setting. ? setting of dspm0 dspm0 = #00000000b ; selects 9 segments ? setting of dspm1 dspm1 = #10110011b ; selects 12 digits, a digit signal cut width of 2/16, and a display cycle of 488 m s (at 4.19 mhz) figure 10-13. display example 10.1.2 key input an example of a program that receives input from an 8 x 4 key matrix is shown. the circuit used for this program uses port 11 (p110 through p117) for the key scan signals and the lower 4 bits (p120 through p123) of port 12 for the key return signals (see figure 10-10). the key scan flag (ksf) is set to 1 while keys are scanned and is cleared to 0 during display. when this flag is set to 1, an interrupt request occurs and keys are input by this interrupt. because not all of the 8 x 4 keys can be input during the time made available by one interrupt request (488 m s), the interrupt request must be issued twice to enable input of all the keys. the timing chart shown in figure 10-14 illustrates how all the keys are input.
267 chapter 10 applications of fip controller/driver figure 10-14. key interrupt timing chart one input key corresponds to 1 bit and is stored in ram. the ram data is set according to the pressed key. when the key is released, the data is cleared. by sequentially testing each bit of ram data starting from the first bit, therefore, the statuses of the keys can be checked. chattering is compensated for by validating the key only if the key data coincides with the corresponding ram bit three times in a row. because 12 digits are displayed and the keys are scanned every 12.688 ms (= 13 x 488 m s (display cycle selectable) x two times (number of interrupts necessary for inputting all the keys)) in this example, chattering of about 25 ms to 38 ms can be eliminated. if a key input is changed, the key change flag (f_khenka) is set. figure 10-15 illustrates how chattering is eliminated. fip0 488 s fip1 fip11 ksf reads first half of key data reads remainder of key data high low key1_new key1_new +7
268 78k/0 series application note figure 10-15. compensating for chattering to prevent unwanted data from being displayed during display, the timing is checked by the key scan flag (ksf) at the beginning and end of key scan processing. 10.1.3 description of package (1) fip display an fip display program is not included in the package. refer to the explanation of initial setting and display data conversion processing in section 10.1.4. (2) key input because key input processing is performed as interrupt processing, the key input processing performed by this package is executed when the intks interrupt request is enabled. ? output parameters key1_old : stores key bit after eliminating chattering key1_new : stores key bit while eliminating chattering scan : stores scanned key data newkeyp : stores ram address used to store next key bit while eliminating chattering f_khenka : set if current key is found to be different from previous key after eliminating chattering bank 2, ax, hl, de, b ksf 12.688 ms - 1st correspondence - 2nd correspondence - 3rd correspondence
269 chapter 10 applications of fip controller/driver name use attributes bytes c_cahta chattering counter saddr 1 key1_old previous key bit input storage area saddr 8 key1_new current key bit input storage area saddr 8 scan key scan data storage area saddr 1 newkeyp next key bit input storage area saddrp 2 work key data transfer area saddr 1 i loop processing work counter saddr 1 b_fip1 stores display data saddr 12 name use f_khenka set upon change in key input. f_keyend set when four keys are scanned. 1 level, 3 bytes ? fip controller/driver ? port 11 ? port 12 (p120 through p123) ? setting of dspm0 dspm0 = #00000000b ; selects 9 segments ? setting of dspm1 dspm1 = #10110011b ; 12 display digits, digit signal cut width of 2/16, and display cycle of 488 m s ? port 11 output mode pm11 = #00000000b ? intks interrupt enable clr1 ksmk the input key data is stored into the key1_new area after the processing of the intks interrupt. all keys are completely input after the intks interrupt request has occurred two times. the determined key is stored into the key1_old area.
270 78k/0 series application note ? set ram as follows after reset and start: newkeyp = #key1_new ; key bit storage ram address scan = #00000001b ; key scan data initial value ? input the key data after testing the key change flag. because the key change flag is not cleared to 0 by interrupt processing, clear this flag after flag test. 10.1.4 example of use in the program example shown below, the initial setting of the key scan work area and display data conversion processing are performed for fip display.
271 chapter 10 applications of fip controller/driver extrn key1_old,key1_new,scan,newkeyp extbit f_khenka ; fip1 equ 0fa70h ; b_fip1: ds 12 ; fip display 1st digit output buf m1 cseg ; res_sta: di ; dspm0=#00000000b ; selects 9 segments dspm1=#10110011b ; 12 display digits, cut width of 2/16, display cycle of 488 m s pm11=#00000000b ; port 11 output mode clr1 ksif ; clears the interrupt request flag clr1 ksmk ; enables intks interrupt ; scan=#00000001b ; key scan data initial value newkeyp=#key1_new ; ei ; intks interrupt (int_key) started by enabled interrupt ; while(forever) ; if_bit(f_khenka) ; key change flag set? clr1 f_khenka ; clears key change flag decode processing for(b=#0;b<#12.b++) ; converts 12 fip display digits into output data and stores that hl=#b_fip1 ; data into the output buf x=[hl+b] ; a=#0 ; ax+=#display ; hl=ax ; a=[hl] ; hl=#fip1 ; [hl+b]=a ; next ; ; fipdat cseg ; display: db 11111100b ; 0 db 01100000b ; 1 db 11011010b ; 2 db 11110010b ; 3 db 01100110b ; 4 db 10110110b ; 5 db 10111110b ; 6 db 11100000b ; 7 db 11111110b ; 8 db 11110110b ; 9 db 11101110b ; a db 00111110b ; b db 10011100b ; c db 01111010b ; d db 10011110b ; e db 10001110b ; f end
272 78k/0 series application note 10.1.5 spd chart [key input processing (intks interrupt processing)] int_key if (during key scan timing) selects bank 2 then work <- #0 hl <- next key bit input storage ram address for (i = #0;i<#4;i++) port 11 <- scan shifts scan bit 1 bit to left key scan time wait processing inputs key return data if (previous bit data 1 current bit data) chattering counter <- #0ffh [hl] <- key return data increments hl register then newkyep <- hl if (ends input of all keys) clears key end flag if (chattering elimination ends) if (previously determined key 1 currently determined key) sets key change flag then then initializes chattering counter newkyep <- new key bit input determination area scan <- key scan initial value if (during key scan timing) then increments chattering counter then sets key end flag else
273 chapter 10 applications of fip controller/driver 10.1.6 program listing ; *********************************************** ; key input processing (intks interrupt) ; *********************************************** ; $pc(044a) public key1_old,key1_new,scan,newkeyp public f-khenka ; veintks cseg at 1ch dw int_key ; chatdat equ 02h ; number of times chattering is eliminated scandat equ 00000001b ; first key scan data ; ; *********************************************** ; ram definition ; *********************************************** ; keyram dseg saddr key1_old: ds 8 ; previous key bit input determination data area key1_new: ds 8 ; current key bit input determination data area c_chata: ds 1 ; chattering counter work: ds 1 ; work area scan: ds 1 ; key scan data storage area i: ds 1 ; work counter area dseg saddrp newkeyp: ds 2 ; next key bit input determination ram address storage area ; keyflg bseg f_khenka dbit ; key change flag f_keyend dbit ; key end flag ; key cseg ; int_key: if_bit(ksf) ; checks flag of intks sel rb2 ; selects bank 2 work=#0 ; hl=newkeyp (ax) ; stores next key storage ram address into hl register for(i=#0;i<=#4;i++) ; p11=scan (a) ; outputs key scan signal a=scan ; shifts scan signal 1 bit to left rol a,1 ; scan=a ; for(b=#0;b<#6;b++) (a) ; scan time wait processing next ; a=p12 ; key return input a &= #0fh ; work=a ; stores key return to work area
274 78k/0 series application note if(a!=[hl]) ; c_chata=#0ffh ; clears chattering counter unless the same as the previous endif ; value [hl]=work (a) ; hl++ ; next ; newkeyp=hl (ax) ; if_bit(f_keyend) ; all keys input? clr1 f_keyend ; if(c_chata>#chatdat) ; end of chattering elimination? de=#key1_old ; hl=#key1_new ; previously determined key 1 currently determined key? for(i=#0;i<#8;i++) ; if([de]!=[hl]) (a) ; sets key change flag set1 f_khenka ; endif ; [de]=[hl] (a) ; de++ ; hl++ ; next ; c_chata=#0 ; clears chattering counter newkeyp=#key1_new ; initializes next key bit input determination ram address scan=#scandat ; initializes key scan data else ; if_bit(ksf) ; checks intks flag c_chata++ ; increments chattering counter if ok endif ; endif ; else ; set1 f_keyend ; endif ; endif ; reti ; end
275 chapter 11 applications of 6-bit up/down counter chapter 11 applications of 6-bit up/down counter the 6-bit up/down counter is incremented or decremented at the valid edge of the ci0/p03/intp3 pin. this counter uses a 6-bit up/down register (udc) to count the number of count pulses input to the ci0/p03/ intp3 pin (see figure 11-1). if the value of the udc coincides with the value of a 6-bit up/down counter compare register (udcc) in ascending count mode, an interrupt request flag (pif3) is set, and the udc is cleared to 0. if the udc underflows in the descending count mode, the interrupt request flag (pif3) is set, and a value of udcc minus 1 is loaded into the udc. the 6-bit up/down counter is controlled by a 6-bit up/down counter control register (udm). figure 11-1. block diagram of 6-bit up/down counter caution when using the 6-bit up/down counter, set the ci0/p03/intp3 pin to input mode (by setting bit 3 (pm03) of port mode register 0 to 1). 6-bit up/down counter compare register (udcc) 6-bit up/down counter (udc) match ci0/p03/inpt3 intp3/intud interrupt request signal 6-bit up/down counter compare register (udcc) 6-bit up/down counter (udc) ci0/p03/inpt3 ? intp3/intud interrupt request signal clear load underflow
276 78k/0 series application note figure 11-2. format of 6-bit up/down counter control register cautions 1. do not set udm0, udm1, and udm3 at the same time as the input of the valid edge of the ci0/p03/intp3 pin. 2. when 1 is written into udm3, the udc is cleared to 0. when the udc is cleared, udm3 is automatically reset to 0. 3. the udc cannot be read or written until data is set in it after reset. 0 7 0 6 0 5 udm4 4 udm3 3 udm2 2 udm1 1 udm0 0 udm2 count operation control 0 stops count operation (count value retained) 1 enables count operation udm symbol ffa8h address 00h at reset r/w r/w udm1 operation mode selection 0 descending count operation 1 ascending count operation udm0 valid edge selection 0 falling edge of ci0 1 rising edge of ci0 udm4 selection of setting signal for intp3 flag 0 set by intp3 interrupt signal 1 set by intud interrupt signal udm3 counter clearing 0 count operation 1 clears counter
277 chapter 11 applications of 6-bit up/down counter 11.1 1-second counter this section provides an example in which the 6-bit up/down counter generates an interrupt request every 1 second when an external frequency of 60 hz is input to ci0. the interrupt processing increments or decrements a ram counter (c_count) by using a count direction flag (f_houkou). (1) description of package ? subroutine name s_updown: subroutine incrementing/decrementing counter ? input parameter f_houkou : up/down count status datau : data stored to compare register (frequency: 60 hz) ? output parameter c_count : stores counter value none name use attributes bytes c_count ram counter saddr 1 name use f_houkou count direction flag (counter counts down when this flag is set) 2 levels, 5 bytes ? 6-bit up/down counter ? set by subroutine s_updown ? intud interrupt enabled ? counting is started when the intud interrupt request is enabled. ? call subroutine s_updown to change the count direction (between up and down).
278 78k/0 series application note (2) example of use extrn s_updown.datau m2 cseg ; res_sta: di ; udc=#0 ; clears 6-bit up/down counter udcc=#datau ; sets value to compare register up udm=#00011110b ; set by intud interrupt signal. ascending count operation. clr1 pif3 ; clears intp3 (intud) interrupt request flag clr1 ksif ; clears interrupt request flag clr1 pmk3 ; enables intud interrupt clr1 ksmk ; enables intks interrupt ei ; if(up/down change) call !s_updown endif (3) spd chart [count processing (intud interrupt processing)] [count direction change routine] count if (counting in negative direction) then decrements ram counter increments ram counter else s_updown stops 6-bit up/down counter then udcc <- selects down counter operation else udcc <- selects up counter operation if (down count direction) starts 6-bit up/down counter operation
279 chapter 11 applications of 6-bit up/down counter (4) program list ; ; *********************************************** ; 6-bit up/down counter (intud) ; *********************************************** $pc(044a) ; ; public c_count,f_houkou ; public s_updownu ; public datau ; ; veintud cseg at 0ch dw count datau equ 60 ; 60 hz cycle ; *********************************************** ; ram definition ; *********************************************** dseg saddr ; c_count: ds 1 ; ram counter bseg ; f_houkou dbit ; count direction flag ; cseg ; count: sel rb2 ; if_bit(f_houkou) ; count direction flag = 1? c_count-- ; yes -> decrements ram counter else ; c_count++ ; no -> increments ram counter endif ; reti ; ; ; *********************************************** ; ram counter up/down subroutine ; *********************************************** s_updown: clr1 udm.2 ; stops count operation if_bit(f_houkou) ; clr1 udm.1 ; down counter operation else ; set1 udm.1 ; up counter operation endif ; set1 udm.2 ; starts count operation ret ; end
280 78k/0 series application note [memo]
281 appendix a spd chart description appendix a spd chart description spd is an acronym derived from structured programming diagrams. structured means logical design and organization using basic logical structures, and involves structuring the logical processes of a program. all programs can be created by only combining basic logical structures (sequencing, selection, repetition). (this is called the structured theorem.) thus, the program flow is clarified by its structure and reliability improves. there are a variety of ways to represent program structure; however, a graphical technique called spd is used at nec. below, the spd symbols used in the spd technique are described and compared to flowchart symbols. table a-1. comparison of spd symbols and flowcharts (1/2) process name spd symbol flowchart symbol sequential processing conditional branch (if) conditional branch (switch) condition process 1 process 2 process n process 2 process 1 condition process 1 process 2 else then process 1 process 2 (if : condition) [then] process 1 process 2 [else] (switch : condition) [case : 1] [case : 2] [case : n] process 1 process 2 process n
282 78k/0 series application note table a-1. comparison of spd symbols and flowcharts (2/2) process name spd symbol flowchart symbol conditional loop (while) conditional loop (until) conditional loop (for) infinite loop connector (while : condition) process (until : condition) process (for : initial values; condition; increment or decrement setting) process (while : forever) process [then] ( if : condition) goto a a process condition process then else process condition else then condition initial values process increment/ decrement else then process process condition else then a a
283 appendix a spd chart description 1. sequential processing sequential processing is executed in the output order from the top to the bottom. ? spd chart 2. conditional branch: 2 branches (if) the processing content is selected based on whether the condition specified in if is true or false (then/ else). ? spd chart examples1. determine whether x is positive or negative. 2. if the signal is red, stop. (if : condition) [then] process 1 process 2 [else] (if : x > 0) [then] x is a positive number x is 0 or a negative number [else] (if : signal = red) [then] stop process 1 process 2
284 78k/0 series application note 3. conditional branch: multiple branches (switch) the condition specified by switch is compared to the states indicated by case and the processing is selected. the two types of processing for a switch statement are the case where only processing in the matched state is executed and the case where processing starts at the matched state and continues on below it. (when processing is not continued, break is written.) also, when no condition is matched, default processing is executed (specifying default is optional). (1) for only the matched state ? spd chart example display the name of a month by entering a character. (switch : input character) [case : ?? [case : ?? [default] display jan. break display feb. break display error (switch : condition) [case : state 1] [case : state 2] [case : state n] [default] process 1 break process 2 break process n process 0 in state 1 : process 1 in state 2 : process 2 in state n : process n when no state is matched : process 0 (execution contents)
285 appendix a spd chart description (2) for processing beginning at the matched state spd chart example communication through a serial interface 4. conditional loop (while) the condition specified in while is evaluated. the processing is repeatedly executed as long as the condition holds. (when the condition does not hold from the beginning, nothing is executed.) ? spd chart example the keys are buffered until the return key is input. (switch : condition) [case : state 1] [case : state 2] [case : state n] [default] process 1 process 2 process n process 0 in state 1 : process 1 -> process 2 ->?> process n in state 2 : process 2 ->?> process n in state n : process n when no state is matched : process 0 (execution contents) (while : condition) processing (while : not the return key) input one character key store input key in buffer (switch : transfer mode) [case : 1] [case : 2] [case : 3] address transmission data transmission break data reception (execution contents) in state 1 : address transmission -> data transmission in state 2 : data transmission in state 3 : data reception
286 78k/0 series application note 5. conditional loop (until) the condition specified in until is evaluated after the process. the process is repeatedly executed until the condition holds. (even when the condition does not hold at the beginning, the process is executed once.) ? spd chart example the value in register b is multiplied by 10 and saved in register a. 6. conditional loop (for) the process is repeatedly executed until the parameter conditions specified in for hold. ? spd chart example beginning at the hl address, clear 256 bytes to 0. (for : initial values; conditions; increment/decrement settings) process set the start address in the hl register (for : workct = #0 ; workct < #256 ; workct++) clear the hl address to 0 increment the hl register (until : condition) process initialize register a set the value in register b save 10 in the counter (until : counter = 0) a = a + b decrement the counter
287 appendix a spd chart description 7. infinite loop by specifying forever as the while condition, the process is repeatedly executed forever. ? spd chart example repeatedly execute the main processing. 8. connector (goto) the specified address is unconditionally branched to. ? spd chart (1) branch to the same module (while : forever) process (while : forever) decode key save the key code in the display area. ? main processing [then] (if : condition) process goto err err
288 78k/0 series application note (2) branch to different modules example at the starting address of the subroutine, the parameter is selected and a wait is set. 9. connector (continue) when one spd module lasts multiple pages, the processing flow is shown below. ? spd chart process process [then] (if : condition) goto err (sub_er) : module name sub_er err set register a to 10 goto wait set register a to 20 goto wait set register a to 30 (until : a = 0) decrement a wait20 wait10 wait30 wait process 1 process 2 1 1 process 3 process 4
289 appendix b revision history appendix b revision history the complete revision history is shown below. the applicable places are shown for the chapter in each edition. edition no. major revisions from the previous edition applicable chapters version 2 the following chapters and sections have been added: throughout sections 2.1 to 2.6 , chapters 3 to 7 , sections 8.1 to 8.4 and 9.1 to 9.3 the following subseries have been added as applicable products: m pd78024, m pd78044a, and m pd780208 the following subseries are no longer applicable products: m pd78002, m pd78002y, m pd78014, and m pd78014y subseries (these subseries are described in basics (i).) m pd78044 subseries m pd78054 and m pd78064 subseries (these subseries are described in basics (iii).) "configuration of 12-digit fip display and key input" has been changed. chapter 10 version 3 the following products have been added as applicable products: throughout m PD78044F, m pd78044h, and m pd780228 subseries, m pd780206, and m pd780208 the following subseries have been dropped as applicable products: m pd78024 and m pd78044a subseries the following subseries have been added in section 1.1. chapter 1 m pd78075b, m pd78075by, m pd780018, m pd780018y, m pd780058, m pd780058y, m pd78058f, m pd78058fy, m pd780034, m pd780034y, m pd780024, m pd780024y, m pd78014h, m pd780964, m pd780924, m pd780228, m pd78044h, m PD78044F, m pd780308, m pd780308y, m pd78064b, m pd78098b, m pd780973, and m pd780805 subseries, and m pd78p0914 table 3-3 has been added. chapter 3 note 2 and caution 2 have been added to figure 4-2. chapter 4 figure 4-4 has been added. a caution has been added to figure 5-5. chapter 5 table 8-2 has been added. chapter 8 note 4 and a caution have been added to figure 8-3. a caution has been added to figure 8-9. section 8.1 the m pd6252 has been defined as a product provided for maintenance purposes only. figure 9-4 has been added. chapter 9
290 78k/0 series application note [memo]
although nec has taken all possible steps to ensure that the documentation supplied to our customers is complete, bug free and up-to-date, we readily accept that errors may occur. despite all the care and precautions we've taken, you may encounter problems in the documentation. please complete this form whenever you'd like to report errors or suggest improvements to us. hong kong, philippines, oceania nec electronics hong kong ltd. fax: +852-2886-9022/9044 korea nec electronics hong kong ltd. seoul branch fax: 02-528-4411 taiwan nec electronics taiwan ltd. fax: 02-719-5951 address north america nec electronics inc. corporate communications dept. fax: 1-800-729-9288 1-408-588-6130 europe nec electronics (europe) gmbh technical documentation dept. fax: +49-211-6503-274 south america nec do brasil s.a. fax: +55-11-889-1689 asian nations except philippines nec electronics singapore pte. ltd. fax: +65-250-3583 japan nec corporation semiconductor solution engineering division technical information support dept. fax: 044-548-7900 i would like to report the following error/make the following suggestion: document title: document number: page number: thank you for your kind support. if possible, please fax the referenced page or drawing. excellent good acceptable poor document rating clarity technical accuracy organization cs 96.8 name company from: tel. fax facsimile message


▲Up To Search▲   

 
Price & Availability of PD78044F

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X